Re: Cancelling state restoration on iOS

2017-07-25 Thread Sixten Otto
You can set a custom restorationClass on a per view controller basis,
passing the process of instantiating the controller during restoration
through your own code that knows how to check whether the document is still
there. (We do something similar in our app in some places to make sure that
our Core Data store is present, and contains the objects the stored state
had been displaying.)

https://developer.apple.com/documentation/uikit/uiviewcontroller/1621472-restorationclass

(It is true, though, that this cannot abort the *entire* restoration
process. Just prune sub-trees of the view controller graph.)


On Tue, Jul 25, 2017 at 12:50 PM, Steve Mills  wrote:

> There doesn't appear to be any way to cancel state restoration other than
> from the app delegate method application:shouldRestoreApplicationState:.
> So if it's trying to restore a view controller for a document that is no
> longer available on the device, I want to cancel the whole restoration. The
> only object that knows which document was previously open is the view
> controller that displays the document. But the only methods offered for
> decoding a VC's state is decodeRestorationStateWithCoder:, which doesn't
> return anything like a BOOL to say if it could be restored or not.
>
> Any ideas?
>
> --
> Steve Mills
> Drummer, Mac geek
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: App Transport Security exceptions App Store signed app

2016-01-27 Thread Sixten Otto
On Wed, Jan 27, 2016 at 10:29 AM, Jens Alfke  wrote:

> I believe that text refers to an *SSL* server "with no certificate, or a
> self-signed, expired, or hostname-mismatched certificate”. There is a
> _separate_ key that allows non-SSL connections.
>

Reading over the rest of the page, I'm fairly certain that's not the case.
Here are a couple of other bits:

Set this key’s value to YES
> ,
> if needed, to:
>
>- Enable connection to an insecure HTTP server
>- Enable connection to an untrusted HTTPS server
>- Enable connection to an HTTPS server for which you want to perform
>your own server trust evaluation
>
> For example, setting the value of a named server’s
> NSExceptionAllowsInsecureHTTPLoads key to YES
> 
>  allows
> insecure HTTP connections to that server.


To use ATS generally but allow connection to a specific server that does
> not support the HTTPS protocol—for example, a media server that your app
> uses—employ the following configuration pattern in your Info.plist file: 
> *[snip
> example using **NSExceptionAllowsInsecureHTTPLoads]*


The only other exception keys that control HTTPS behavior are
NSExceptionRequiresForwardSecrecy and NSExceptionMinimumTLSVersion, neither
of which seems to fit the role you're talking about.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: App Transport Security exceptions App Store signed app

2016-01-27 Thread Sixten Otto
On Tue, Jan 26, 2016 at 11:18 PM, Jens Alfke  wrote:

> I believe you’re using the wrong key. If you need non-SSL connections to
> work, the key you want is NSAllowsArbitraryLoads. The key you’re using is
> for situations where you make an SSL connection but the SSL server doesn’t
> meet ATS’s security requirements — e.g. its certificate is self-signed or
> expired.
>

According the docs, it's also for the case where the connection needs to be
made over non-S HTTP: "With this key’s value set to YES
,
your app can make secure connections to a secure server but can also
connect insecurely to a server with no certificate, or a self-signed,
expired, or hostname-mismatched certificate." (
https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
)

Which you might want to do if you have an app where you really don't want
to allow connections to absolutely anything (which NSAllowsArbitraryLoads
does), but there's a specific, known host/domain that you need that doesn't
support TLS.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Custom UIViewController transitions with segues

2015-12-30 Thread Sixten Otto
Are you maybe looking for the UINavigationControllerDelegate method that
lets you provide an animation controller for the push? That appears to be
the way one hooks into the operation of the navigation controller in order
to override the default animations.

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationControllerDelegate_Protocol/#//apple_ref/occ/intfm/UINavigationControllerDelegate/navigationController:animationControllerForOperation:fromViewController:toViewController
:


On Wed, Dec 30, 2015 at 7:48 PM, Rick Mann  wrote:

>
> > On Dec 30, 2015, at 18:20 , Rick Mann  wrote:
> >
> >
> >> On Dec 30, 2015, at 18:14 , Roland King  wrote:
> >>
> >>
> >>> On 31 Dec 2015, at 09:12, Rick Mann  wrote:
> >>>
> >>> I have a UICollectionView in a UINavigationController, and I'd like to
> customize the transition from one to the next on push. So I set up the
> first VC as UIViewControllerTransitioningDelegate, and in
> prepareForSegue(_:sender:) set the destination VC's transitioningDelegate
> to self.
> >>>
> >>> But my delegate methods never get called. The docs say to set
> modalPresentationStyle to .Custom, but that has no effect (also, it's a bit
> weird since this is not technically a modal presentation, is it?).
> >>>
> >>> Search for solutions online turns up only custom segues, which is not
> really what I want.
> >>>
> >>> Is it even possible to do this with segues? What am I missing?
> >>>
> >>> TIA,
> >>
> >> My thought here is that push != present, ie
> pushViewController(_:animated) doesn’t do the same thing as
> presentViewController(_:animated:completion) and that push calls the former
> and other modes call the latter. I dunno what I’d try, the whole
> UIViewController custom transitioning thing confuses the bananas out of me
> and I never found the WWDC videos on them to be as helpful as I wished.
> Perhaps change the push to a present to get it on the screen, then when
> you’re done with the transition, call pushViewController( vc, animated :
> false ) to fix up the nav stack. That will probably look really ugly as the
> nav bar will likely just snap to the new content.
> >>
> >> There’s probably 18 other ways to do it. I’d bung some hooks into any
> methods I could find which run early in the viewcontroller presentation
> lifecycle and see if there’s a transition coordinator or animation
> coordinator or whatever objects transitions create which I could hook into
> and animate alongside.
> >>
> >> In general .. having fiddled with custom transitions when the were new
> and shiny .. I don’t bother with them any more.
> >
> > It seems to be a common ocurrence that Apple introduces a "helpful" new
> way to do things that aren't fully integrated with existing "new" (and
> definitely not deprecated. e.g. segues) ways of doing things, and the
> documentation and examples are lacking. Bruce Nilo's 2013 presentation on
> the subject was particularly lacking in information.
> >
> > Having said that, I found this sample code (which did not turn up when
> searching the sample code for "transition"), which hopefully works. My
> biggest beef at this point is that the segue *must* be a modal presentation
> segue (in fact, it seems all custom transitions are for modal presentation
> only), which seems like a silly limitation, and is not well-documented.
> >
> >
> https://developer.apple.com/library/ios/samplecode/SegueCatalog/Introduction/Intro.html
> >
> > You're looking for the "Modal" button in that app, which has a custom
> segue that uses the transition stuff.
>
> Welp, that doesn't work in the push transition. It hides the
> UINavigationBar. The sample code shows it as a modal transition that takes
> over the screen, but I want to do a push transition.
>
> Thing is, it doesn't seem that any of the transition stuff works properly
> if you make it anything other than a modal (i.e. not a show/push).
>
> Goddammit, Apple.
>
> --
> Rick Mann
> rm...@latencyzero.com
>
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Problem loading a CoreDataModel from a Static library in Swift

2015-12-15 Thread Sixten Otto
You might want to include some of your code for loading the model, to make
this discussion less hypothetical.

Also, when you say that "ObjC works just fine", what does that mean?
Objective-C code in the same app that's trying to load the same model that
Swift code in that app can't load? Or some separate test written in
Objective-C?

On Mon, Dec 14, 2015 at 6:55 AM, Jim Adams  wrote:

> Not sure where to ask this question. I just started trying Swift to see
> how my company’s SDK could be integrated. I am getting this error:
> CoreData: Failed to load optimized model at path …/modle.omo’
>
> This is a static library with an associated bundle that contains the
> CoreData model. ObjC works just fine. The code seems to run but the
> warning/error is disturbing. I searched all over Google and only found a
> mention of the Google Maps SDK. There was no post of the solution other
> than re-compiling with Xcode 7. Since we already build with Xcode 7 I am at
> a loss. Anyone else seen this?
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Is it possible to transfer data by using light

2015-09-21 Thread Sixten Otto
On Sun, Sep 20, 2015 at 9:55 PM, Jens Alfke  wrote:

> But honestly, if you're going this route, it will be much faster to
> transmit QR codes, since each code contains thousands of bits.
>

Especially given that recent versions of iOS can detect and decode QR codes
automatically, much like face detection.

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVMetadataMachineReadableCodeObject_Class/index.html

https://developer.apple.com/library/ios/documentation/QuartzCore/Reference/CIQRCodeFeature/


> On Sep 20, 2015, at 7:21 PM, ico  wrote:
> >
> > After reading all of the replies, no one mentioned how to use iPhone to
> > detect the light changes (bright and dark) in codes, I just have no clue
> > how to make it works as long as I remember developers have no right to
> > access the light sensor, so I guess we have to use camera to achieve
> this,
> > but I just don't know how. Can anyone point me to something to read so I
> > can start digging into this and make the whole thing start to work?
> >
> > Thank you all.
> >
> > On Fri, 18 Sep 2015 at 20:38 Michael David Crawford <
> mdcrawf...@gmail.com>
> > wrote:
> >
> >> Do iOS devices support Trusted Computing in hardware?  If so is it
> >> accessible to userspace apps?
> >>
> >> If so, you could store your phones secret in a write-only register.
> >> For the profoundly paranoid, even the duplication of your storage
> >> would not yield your phone's secret, The Bad Guy would need your
> >> personal phone.
> >>
> >> Modern Macs - to the best of my knowledge - provide trusted computing
> >> chips, on can access them from userspace with a modest bit of code.
> >> Michael David Crawford P.E., Consulting Process Architect
> >> mdcrawf...@gmail.com
> >> http://mike.soggywizard.com/
> >>
> >>  One Must Not Trifle With Wizards For It Makes Us Soggy And Hard To
> >> Light.
> >>
> >>
> >>> On Fri, Sep 18, 2015 at 3:12 AM, Maxthon Chan 
> wrote:
> >>> The "over-the-shoulder" issue can be avoided using what is effectively
> a
> >> Diffie-Hellman on top of QR codes. This can be done using front-facing
> >> cameras on two devices placed face-to-face.
> >>>
> >>> Sent from my iPhone
> >>>
>  On Sep 18, 2015, at 00:46, Pascal J. Bourguignon <
> p...@informatimago.com>
> >> wrote:
> 
> 
> 
> > On 17/09/15 17:32, Michael David Crawford wrote:
> > And what the man said: I myself experience seizures in which I lose
> > consciousness for as long as three weeks.  Before they were diagnosed
> > I would experience seizures while driving my car then suddenly find
> > myself in unfamiliar places without any clue how I got there.
> >
> > I don't know for sure but strongly suspect that modern computer user
> > interfaces caused my seizure disorder as well as that of my cousin.
> > Seizures are not otherwise found among any of our blood relatives.
> 
>  But then if you don't use the whole screen, but only the area that
>  should be in front of the camera of the superposed phone, then users
>  shouldn't be subjected to much stroboscopic light.
> 
>  Having the objective so close from the light source does not allow
>  the camera to distinguish pixels; for example, a black to white
>  transition takes about 1/10 of the height of the camera view.
>  But this means that you might still able to transmit about ten pixels
> >> at once,
>  and you can multiply that by a number of color that you can detect
> >> reliably
>  being that out of focus. Basically, I would expect 8 colors to be
> >> clearly
>  distinguishable.  Actually, probably more colors should be
> >> distinguishable,
>  if you can filter out the interferences due to the grid of the camera
> >> vs.
>  the grid of the screen. So assume 4 bits for the color, and 9 areas,
>  that's 36 bit/moment, and you should be able to do 30 moment/second,
>  for a total of 1080 bit/second.  A little less for ECC, about 1 KB/s
>  is not too bad.  It's good enough to transmit a good private key, and
> >> then
>  transfer the data thru wifi.
> 
> 
>  Of course, if you move the camera out to focus on the screen, then
>  you can transmit at a higher speed things like QR codes, but they
>  could also be seen over the shoulder by high resolution cameras.
> 
>  --
>  __Pascal J. Bourguignon__
>  http://www.informatimago.com/
> 
>  ___
> 
>  Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
>  Please do not post admin requests or moderator comments to the list.
>  Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
>  Help/Unsubscribe/Update your Subscription:
>  https://lists.apple.com/mailman/options/cocoa-dev/max%40maxchan.info
> 
>  This email sent to m...@maxchan.info
> >>>
> >>> ___
> >>>
> >>> Cocoa-dev ma

Re: Improve performance of data structure saved to disk

2015-08-06 Thread Sixten Otto
On Thu, Aug 6, 2015 at 9:31 AM, Jens Alfke  wrote:

> As far as I know, there’s no good Cocoa solution for super-simple
> persistence — something like a persistent NSDictionary that can efficiently
> store any number of keys. This would be pretty easy to implement using a
> bare-bones key/value store like Berkeley DB, Tokyo Cabinet, LevelDB, LMDB,
> ForestDB, etc. (You can even use SQLite with a very simple key/value
> schema.)
>

It's not Apple-provided, but YapDatabase (
https://github.com/yapstudios/YapDatabase) is a key-value store implemented
on top of SQLite that's usable on iOS and OS X, and which I've seen
recommended a lot in this sort of conversation, and which should be much
easier to adopt that another cross-platform binary store. It also has lots
of extensions to support things like querying and change notifications.

For the record, I agree that it's probably overkill in this instance.

(Also, I'll note for the record that Tokyo/Kyoto Cabinet aren't going to be
usable in an App Store app without a commercial license.)

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: C Sharp?

2015-07-14 Thread Sixten Otto
On Tue, Jul 14, 2015 at 10:48 AM, Dave  wrote:

> Does anyone know of a tool/framework that allows C# code to be compiled
> and called from Cocoa?
>

You mean like http://xamarin.com/platform ?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Anyone recommend Dash?

2015-07-09 Thread Sixten Otto
On Thu, Jul 9, 2015 at 12:02 AM, Roland King  wrote:

> I did get an update the other day which just told me a new version is on
> the way, or just released perhaps. I think I have Dash 2, this is Dash 3
> and is an extra 10 bucks which I will probably end up paying eventually.
> How that works thru the appstore I’m not entirely sure - I didn’t think you
> could do paid upgrades through the appstore.
>

You can't. Dash 3 is a new, separate app, with its own IAP. (Much as Dash 2
was distinct from the original.)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Getting a server to trust the client. (iOS)

2015-06-22 Thread Sixten Otto
Using client-side certificates in TLS is pretty standard stuff, and should
be well-supported by the system. You might start here:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/AuthenticationChallenges.html

The biggest issue with something like this, or any scheme where you're
trusting the client based on information that was packaged in the app, is
that the app necessarily contains the information some bad actor would need
to have to build a malicious client that you probably don't want to trust.
(Same with things like encryption keys, API keys, shared passwords, and so
on.) On the other hand, maybe that isn't the kind of risk you're trying to
mitigate.

Can you say anything more about what kind of app/service this is, and what
sorts of threats you're trying to protect against?

Do you have any way of knowing who the valid users should be ahead of time,
or communicating with them outside of the app?

Sixten


On Mon, Jun 22, 2015 at 6:43 AM, Alex Zavatone  wrote:

> We're all familiar with using a SSL cert to get a client to trust a
> server, but we're looking at is getting a server to trust that a trusted
> client is allowed to access it.
>
> I was thinking of embedding an SSL cert within the iOS app and validating
> against that, but I'm sort of lost on a way to start.
>
> If this approach seems valid, do any of you have any ideas on any sites
> where I could start reading up on this?
>
> If this approach doesn't seem valid, do any of you have any suggestions on
> what might be a better approach?
>
> Thanks much in advance,
>
> Alex Zavatone
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: 'nuther dumb question

2014-05-16 Thread Sixten Otto
On Fri, May 16, 2014 at 4:46 PM, William Squires wrote:

>   Why doesn't NSData have a +[NSData dataWithString:(NSString *)] or
> -[NSData initWithString:(NSString *)] method? i.e. how do I convert the
> contents of an NSString object into an NSData object?


Try -[NSString dataUsingEncoding:] or
-[NSString dataUsingEncoding:allowLossyConversion:] ?

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: VC# vs. ObjC and partial abstract classes

2014-03-19 Thread Sixten Otto
On Tue, Mar 18, 2014 at 5:30 PM, William Squires wrote:

> My best guess is to:
>
> 1) Make an ObjC class, and have it implement those methods that subclasses
> don't have to override. For those the subclasses must override, implement a
> stub that raises an exception if a message is sent to it (as ObjC doesn't
> have an "abstract" keyword).
>

This is about the best you're going to do in terms of being able to "force"
subclasses to override those methods.


> 2) Create a ObjC protocol with the same name as the above class, and
> copy/paste the method prototypes from the ObjC class' .h file into the
> protocol's .h file.
> 3) Go back to the ObjC class, and have it implement its own interface.
>

This doesn't really seem to buy you much. If the base class conforms to the
protocol, then any methods required by the protocol must be implemented by
that base class. The base class wouldn't have to implement optional
methods, but neither would the subclasses. The net impact on the subclasses
is pretty much nothing.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: VC# vs. ObjC and partial abstract classes

2014-03-19 Thread Sixten Otto
On Wed, Mar 19, 2014 at 12:38 AM, Luther Baker wrote:

> On Wed, Mar 19, 2014 at 12:14 AM, Sixten Otto  wrote:
>
>> The significant difference, though, between an abstract class in Java or
>>
> C#, and a protocol in Objective-C, is that the former may have substantial
>> implementation associated with it for the benefit of subclasses, and just
>> not be directly instantiable.
>>
>
> The original poster's first paragraph uses and defines the phrase "partial
> abstract class" which is what you're describing here. I think we're all
> good with what you're saying. But the point to which you are actually
> responding to is in regard to a point I made in response to Kyle's
> suggestion which had to do with the author's self described "pure abstract
> class" which we can infer has NO implementation.
>

You're right. I missed that qualifier, and in that light, this part of my
reply doesn't add anything to the conversation.

(I'm hard pressed to think of much use for such a "pure" abstract class,
though; what could you do with such a thing that couldn't be done with
interfaces.)


> And more to the point, I think the original poster already knows what you
> are saying. I think he is asking for thoughts regarding his approach to
> simulating a notional Abstract Class via mix of @protocols and @classes in
> Objective-C. He clearly knows he can't do it with @protocols alone.
>
>>
I did try to address that at the end of my message:


> Another way that Objective-C accomplishes some of the same goals is through
>> delegation. You don't, for instance, subclass a UITableView to provide its
>> data, you provide a delegate that conforms to UITableViewDataSource; which
>> protocol does have a couple of required methods.
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: VC# vs. ObjC and partial abstract classes

2014-03-18 Thread Sixten Otto
On Tue, Mar 18, 2014 at 7:29 PM, Luther Baker  wrote:

> A _better_ analogy to an Objective-C @protocol would be a formal Java
> interface.
>

Sure. And the same in C# (which the OP was asking about).


> So, Kyle may have good reasons for his answer - but if I understand the
> essence of your question, I would say yes, a pure "abstract class" (where
> no methods are implemented) or a formal "interface" (where method
> signatures have no implementation) in a language like Java ... would both
> indeed be _similar_ to a formal @protocol in Objective-C.
>

The significant difference, though, between an abstract class in Java or
C#, and a protocol in Objective-C, is that the former may have substantial
implementation associated with it for the benefit of subclasses, and just
not be directly instantiable.

(Something like UIKit's UIResponder might be a good choice for this kind of
thing, if Objective-C supported it: it provides a lot of common machinery
you wouldn't want each conforming class to implement separately, but also
isn't something you'd use on its own.)

Another way that Objective-C accomplishes some of the same goals is through
delegation. You don't, for instance, subclass a UITableView to provide its
data, you provide a delegate that conforms to UITableViewDataSource; which
protocol does have a couple of required methods.

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: "No options" constant

2014-03-14 Thread Sixten Otto
On Thu, Oct 17, 2013 at 5:05 PM, Sixten Otto  wrote:

> Let me be clear: I'm not talking about borrowing the "none" constant from
> Enumeration A and using it when calling something that expects values from
> Enumeration B. I agree that that would be confusing, and possibly get me
> into trouble one day. The thing that I was trying to remember, and that
> apparently no one recognizes from my description, was a standalone thing.
> More like NULL or NO.
>

I just happened to run across the constant that I has been trying to
remember. And because this conversation was such fun the first time, I
thought I'd follow up for posterity:

The constant in question is kNilOptions. The reason no one remembered it is
almost certainly that it's declared in MacTypes.h. (See it here, for
example:
https://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/MacTypes.h
)

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Two kinds of NSManagedObject fault?

2014-03-07 Thread Sixten Otto
Not as I recall, but it's worth noting that isDeleted only returns YES
between the time that a managed object is marked for deletion, and when
that change is committed. After that, it returns NO (which kind of sucks).
The managedObjectContext will also be nil at that point (though that CAN
happen in other circumstances).


On Fri, Mar 7, 2014 at 2:47 PM, Rick Mann  wrote:

>
> On Mar 7, 2014, at 13:44 , Sixten Otto  wrote:
>
> > FWIW: trying to access a managed object that has been deleted, but to
> which something still has a reference, can produce symptoms like the second
> kind of access you describe.
>
> Even the isDeleted property?
>
> >
> > Sixten
> >
> >
> > On Fri, Mar 7, 2014 at 2:21 PM, Rick Mann  wrote:
> > It seems that objects can be faulted in two ways. In the first, an
> access will load the data and things are fine. In the second, an access
> results in a crash because the fault could not be fulfilled.
> >
> > Is there a way to tell these two apart?
> >
> > --
> > Rick
> >
> >
> >
> >
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > Please do not post admin requests or moderator comments to the list.
> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> >
> > Help/Unsubscribe/Update your Subscription:
> > https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
> >
> > This email sent to hims...@sfko.com
> >
>
>
> --
> Rick
>
>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Two kinds of NSManagedObject fault?

2014-03-07 Thread Sixten Otto
FWIW: trying to access a managed object that has been deleted, but to which
something still has a reference, can produce symptoms like the second kind
of access you describe.

Sixten


On Fri, Mar 7, 2014 at 2:21 PM, Rick Mann  wrote:

> It seems that objects can be faulted in two ways. In the first, an access
> will load the data and things are fine. In the second, an access results in
> a crash because the fault could not be fulfilled.
>
> Is there a way to tell these two apart?
>
> --
> Rick
>
>
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Class name as NSString and problem with NSLog?

2014-03-06 Thread Sixten Otto
First off, you don't need to build the string ahead of time; NSLog()
supports vararg formatting:
NSLog(@"<%@> -(void)myMethod", myClassName);

Off the top of my head, I can't recall whether Class objects get formatted
as the class name automatically:
NSLog(@"<%@> -(void)myMethod", [self class]);  // works??

But you can certainly convert to a string with the name of the class
explicitly with NSStringFromClass():
NSLog(@"<%@> -(void)myMethod", NSStringFromClass([self class));


On Thu, Mar 6, 2014 at 11:21 AM, William Squires wrote:

>   Given an object, and a method within, is there some way to get the name
> of the class of the object as an NSString?
>   For that matter, what I want to do is something like this:
>
> Class MyClass
> "MyClass.h"
> #import 
>
> @interface MyClass : NSObject
>
> ...
>
> -(void)myMethod;
>
> @end
>
> "MyClass.m"
> #import "MyClass.h"
>
> @implementation MyClass
>
> ...
> -(void)myMethod
> {
> NSString *myClassName = ???; // What can I put here besides a literal
> @"MyClass"?
>
> NSString *fooText = [NSString stringWithFormat:@"<%@> -(void)myMethod",
> myClassName];
> NSLog(fooText); // Yellow triangle on this line
> }
> ...
> @end
>
> so that when the myMethod message is sent to an object of MyClass, the
> output should be:
>
> <>:  -(void)myMethod
>
> on the output pane when debugging - "<>" just comes from the
> NSLog call.
>
>   Also, when I do this (using a literal NSString constant for myClassName
> above), Xcode marks the line with NSLog with a yellow triangle, and
> disclosing it says something about passing an NSString instance as being
> "unsecure". Can this warning be turned off? It seems silly to do:
>
> NSLog(@"%@", fooText);
>
> just to avoid this warning.
>   By using this strategy, if several classes implement the same message, I
> can tell which instance received the message during debugging; this is
> handy when iterating over containers (such as NSArray), and passing the
> same message to multiple objects, or when passing messages to objects of
> subclasses that override the behavior of their super.
>   TIA!
>
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSPredicate speed improvement?

2014-03-02 Thread Sixten Otto
Sorry for the delay in getting back to you; trying to actually have a
weekend. :-)

First: I'm assuming that your model looks something like this, with two
entities, and reciprocal to-many relationships between then (whether you're
using exactly the same names or not): http://tinypic.com/r/11v2m8n/8

If we weren't talking about a fetched results controller, getting all books
for a library would be quite simple, of course: just follow the
relationship.

// without dedicated subclasses
NSManagedObject *library; // assume this gets initialized somewhere
NSSet *booksDirect = [library valueForKey:@"books"];

// with dedicated subclasses
FooLibrary *library;
NSSet *booksDirect = [library books];

With the fetched results controller, you do need to use a fetch request to
get the books, but the relationship is still the way to go:

// get the library's books through a fetch request
NSFetchRequest *fetchBooks = [NSFetchRequest
fetchRequestWithEntityName:@"Book"];
[fetchBooks setPredicate:[NSPredicate predicateWithFormat:@"ANY
libraries == %@", library]];

In this case, because the Book -> Library relationship is to-many, the
predicate needs to check whether ANY of the book's libraries match the
particular library you care about. (The value inserted into the predicate
can be either the library, or the library managed object ID, which can be
handy in the case where don't have the entire library object loaded.)

Sixten



On Sat, Mar 1, 2014 at 8:33 AM, Koen van der Drift <
koenvanderdr...@gmail.com> wrote:

> You are right about the [cd], which is not supposed to be here, blame it
> on poor copy-paste skills.
>
> So how can I fix the predicate to compare entities?
>
> - Koen.
>
> On Mar 1, 2014, at 10:22 AM, Sixten Otto  wrote:
>
> Two things:
>
> 1. No, doing a string comparison with contains (and case and diacritical
> folding active) is one of the slower kinds of string comparison. Straight
> equality should be much faster.
>
> 2. You say that there are two entities, with a relationship defined. Why,
> then, are you doing a string comparison in this predicate? Checking the
> value of the relationship should be much faster.
>
> Sixten
>
>
> On Sat, Mar 1, 2014 at 5:22 AM, Koen van der Drift <
> koenvanderdr...@gmail.com> wrote:
>
>> Consider two entities in a many-to-many relationship: Library and Book.
>> In a NSFetchResultController backed UITableView, I like to show all the
>> books from one library, so I constructed the following fetch request:
>>
>> NSFetchRequest *fetchRequest = [NSFetchRequest
>> fetchRequestWithEntityName: @"Book"];
>> NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:
>> @"date" ascending: YES];
>> [fetchRequest setSortDescriptors: @[sort]];
>>
>> NSPredicate *predicate = [NSPredicate predicateWithFormat:
>> @"libraries contains[cd] %@", self.library];
>> [fetchRequest setPredicate: predicate];
>>
>> which is then fed into the NSFetchedResultController when the view opens.
>>
>> There is a noticeable delay of a few 100 ms when the view opens, and I
>> suspect that the predicate I have is not optimal by using 'contains'.
>>
>> Is there a way to improve on this?
>>
>> Thanks,
>>
>> - Koen.
>>
>>
>> ___
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>>
>> This email sent to hims...@sfko.com
>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSPredicate speed improvement?

2014-03-01 Thread Sixten Otto
Two things:

1. No, doing a string comparison with contains (and case and diacritical
folding active) is one of the slower kinds of string comparison. Straight
equality should be much faster.

2. You say that there are two entities, with a relationship defined. Why,
then, are you doing a string comparison in this predicate? Checking the
value of the relationship should be much faster.

Sixten


On Sat, Mar 1, 2014 at 5:22 AM, Koen van der Drift <
koenvanderdr...@gmail.com> wrote:

> Consider two entities in a many-to-many relationship: Library and Book. In
> a NSFetchResultController backed UITableView, I like to show all the books
> from one library, so I constructed the following fetch request:
>
> NSFetchRequest *fetchRequest = [NSFetchRequest
> fetchRequestWithEntityName: @"Book"];
> NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:
> @"date" ascending: YES];
> [fetchRequest setSortDescriptors: @[sort]];
>
> NSPredicate *predicate = [NSPredicate predicateWithFormat: @"libraries
> contains[cd] %@", self.library];
> [fetchRequest setPredicate: predicate];
>
> which is then fed into the NSFetchedResultController when the view opens.
>
> There is a noticeable delay of a few 100 ms when the view opens, and I
> suspect that the predicate I have is not optimal by using 'contains'.
>
> Is there a way to improve on this?
>
> Thanks,
>
> - Koen.
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSFetchedResultsController sort on synthesized property?

2014-02-27 Thread Sixten Otto
The fetched results controller needs to be able to do its sorting in the
database (assuming a SQLite store). The section keypath itself doesn't
necessarily need to be a persistent property, as long as its values match
the ordering of the sort descriptors. (For instance: a table that sections
the results by day might have a transient property that calculates the day
from the date, but actually sorts the results by the persistent date
property.)

Sixten


On Wed, Feb 26, 2014 at 9:21 PM, Rick Mann  wrote:

> It seems that I can't sort on a read-only synthesized property in my
> NSManagedObject subclass. I'd like to sort a bunch of stuff into some
> sections, but the definition of a section is somewhat complex, depending on
> multiple other properties. So, I defined a property "section" like this:
>
> - (NSUInteger)
> section
> {
> if (self.active.boolValue)
> {
> return 1;
> }
> else if (self.dateClosed != nil)
> {
> return 3;
> }
> else
> {
> return 2;
> }
> }
>
> + (NSSet*)
> keyPathsForValuesAffectingSection
> {
> return [NSSet setWithObjects: @"active", @"dateClosed", nil];
> }
>
> I similarly define a "sectionName" property, but the
> NSFetchedResultsController has no problem using that to section the table
> view.
>
> Unfortunately, I get an exception when I attempt to execute the fetch
> while sorting on "section". Is there any way to accomplish what I need?
>
>
> --
> Rick
>
>
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Any way to determine where a string will be truncated?

2014-01-17 Thread Sixten Otto
I did get a proof of concept working with the TextKit classes. Turns out to
be possible, but more complicated and more moving parts than I would have
(naively?) expected. Beyond the complexity, the main drawback to that
approach is that it won't work on iOS 6, which the app in question still
supports.

I'd also considered trying something similar with Core Text. I *think* that
it might be possible to use a framesetter to do this, but I haven't
explored that yet. I'm sure it'd be at least as complicated as the TextKit
approach, though.

Was really hoping there was a two-line solution that was just eluding me.


On Fri, Jan 17, 2014 at 12:00 PM, T.J. Usiyan  wrote:

> I think that you might want NSLayoutManager. This depends on how you are
> displaying the text, NSLayout manager can allow you to both find out and
> change where truncation will happen. WWDC 2013 session 220 has some info
> about iOS's version of this which is very similar to Cococa's.
>
> TJ
>
>
> On Fri, Jan 17, 2014 at 10:43 AM, Sixten Otto  wrote:
>
>> Using the methods in the UIStringDrawing category on NSString, it's pretty
>> straightforward to measure the size of a string as it will appear on
>> screen, or to draw it into some constrained area. And I love that UIKit
>> handles all of the logic to truncate the string to fit.
>>
>> But I find myself in a situation where I'd like to actually obtain the
>> truncated version of the string. That is, given some text and a bounding
>> area, to have the system figure out how much will fit, and then tell me
>> that (whether returning the truncated string directly, or giving me a
>> character range that would fit, or whatever). So far, though, I can't find
>> any means to accomplish that.
>>
>> I feel like I must be missing something obvious, and I'm hoping someone
>> can
>> point me in the right direction.
>>
>> Thanks,
>> Sixten
>> ___
>>
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/griotspeak%40gmail.com
>>
>> This email sent to griotsp...@gmail.com
>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Any way to determine where a string will be truncated?

2014-01-17 Thread Sixten Otto
Using the methods in the UIStringDrawing category on NSString, it's pretty
straightforward to measure the size of a string as it will appear on
screen, or to draw it into some constrained area. And I love that UIKit
handles all of the logic to truncate the string to fit.

But I find myself in a situation where I'd like to actually obtain the
truncated version of the string. That is, given some text and a bounding
area, to have the system figure out how much will fit, and then tell me
that (whether returning the truncated string directly, or giving me a
character range that would fit, or whatever). So far, though, I can't find
any means to accomplish that.

I feel like I must be missing something obvious, and I'm hoping someone can
point me in the right direction.

Thanks,
Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIPopoverController and UIToolbar interactions

2014-01-13 Thread Sixten Otto
Yeah, I mentioned that in my last paragraph.


On Mon, Jan 13, 2014 at 3:33 PM, Gideon King  wrote:

> …or set your passthroughViews to nil *after* your presentPopover call and
> have it just dismiss the popover as normal when you tap something on the
> toolbar.
>
> Regards
>
> Gideon
>
> On 14 Jan 2014, at 8:28 am, Sixten Otto  wrote:
>
> > I tend to agree that it's problematic, but it is deliberate. From the
> > documentation:
> >
> >
> …
>
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIPopoverController and UIToolbar interactions

2014-01-13 Thread Sixten Otto
I tend to agree that it's problematic, but it is deliberate. From the
documentation:

Discussion

When presenting the popover, this method adds the toolbar that owns the
button to the popover’s list of passthrough views. Thus, taps in the
toolbar result in the action methods of the corresponding toolbar items
being called. If you want the popover to be dismissed when a different
toolbar item is tapped, you must implement that behavior in your action
handler methods.

https://developer.apple.com/library/ios/documentation/uikit/reference/UIPopoverController_class/Reference/Reference.html#//apple_ref/doc/uid/TP40009306-CH1-SW18

Unfortunately, while you can set the passthrough views back to nil after
the popover is presented, the system will re-add the bar if it re-presents
the popover (such as when the device is rotated). I filed rdar://13774176
about that.



On Mon, Jan 13, 2014 at 3:16 PM, Rick Mann  wrote:

> I have an iPad app with a UIToolbar across the top, and a couple of
> UIPopoverControllers that come out of buttons in that toolbar.
>
> One of the things I notice is that when a popover is open, you can still
> click on other buttons in the UIToolbar, and it doesn't go through the
> normal UIPopoverController delegate chain (i.e.
> -popoverControllerShouldDismissPopover:). This is really problematic, as
> it's really inappropriate for those items to be tapped while the popover is
> showing.
>
> Any suggestions?
>
> --
> Rick
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: "No options" constant

2013-10-17 Thread Sixten Otto
On Thu, Oct 17, 2013 at 3:15 PM, Quincey Morris <
quinceymor...@rivergatesoftware.com> wrote:

> Yeah. It seems to me there are two prime reasons to use a specific
> constant:
>

But I'm explicitly talking about APIs where there exists no such constant,
and calling code would generally use a literal zero. If Apple wants to
provide a new NSStringCompareOptions value (for example) that's equal to
zero, and meaning "none of these," that would be fantastic, and I'd use it.
But today, there is no such thing.

Let me be clear: I'm not talking about borrowing the "none" constant from
Enumeration A and using it when calling something that expects values from
Enumeration B. I agree that that would be confusing, and possibly get me
into trouble one day. The thing that I was trying to remember, and that
apparently no one recognizes from my description, was a standalone thing.
More like NULL or NO.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: "No options" constant

2013-10-17 Thread Sixten Otto
On Thu, Oct 17, 2013 at 11:22 AM, Seth Willits  wrote:

> I would be hesitant to get used to such a constant.
>

I'll bite: why?


> Many APIs have their own constants for default options. (Search for
> DefaultOptions, OptionsDefault, NoOptions, and OptionsNone.)
>

Obviously. And those generally stand out quite clearly in the
documentation. But a like number (or more?), including the examples I
cited, do not.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

"No options" constant

2013-10-17 Thread Sixten Otto
This has been driving me crazy, and hopefully someone on the list will know
off the top…

I remember coming across a reference somewhere recently to a constant
defined in Foundation or Core Foundations (I think!) that has a zero value,
and semantically means "I choose no options". Something that would be used
in place of a literal zero when calling methods like +[UIView
animateWithDuration:delay:options:animations:completion:] or -[NSString
rangeOfString:options:] that take a set of option flags.

Of course, I didn't bookmark the reference. And now I have NO IDEA where I
saw it. Google, NSHipster, and searching the documentation haven't turned
anything up. (And that fruitless searching bugs me way more than continuing
to use a literal zero.)

Can anyone jog my memory?

Thanks,
Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: NSAttributedString mysteriously truncated too soon

2012-11-08 Thread Sixten Otto
Out of curiosity, does it matter if you change this line:
  [content addAttribute:NSParagraphStyleAttributeName value:para
range:NSMakeRange(title.length,1)];

to this?
  [content addAttribute:NSParagraphStyleAttributeName value:para
range:NSMakeRange(title.length,blurb.length)];

I don't know that it would, it just stuck out at me as a little odd to only
add the paragraph style to one character.


On Thu, Nov 8, 2012 at 2:23 PM, Matt Neuburg  wrote:

> I have a tall UILabel with numberOfLines 0 (meaning infinite). The problem
> remains the same even if numberOfLines is some large finite number such as
> 20, so that's not the source of the problem.
>
> I am creating an attributed string like this:
>
> NSString *s1 = @"The Gettysburg Address, as given by A. Lincoln on a
> certain occasion\n";
> NSString *s2 = @"Four score and seven years ago, our fathers brought
> forth upon this continent a new nation, conceived in liberty, and dedicated
> to the proposition that all men are created equal.";
>
> NSString* title = s1;
> NSMutableAttributedString* content = [[NSMutableAttributedString alloc]
>   initWithString:title
>   
> attributes:@{NSFontAttributeName:[UIFont
> fontWithName:@"Arial-BoldMT" size:15],
>
> NSForegroundColorAttributeName:[UIColor colorWithRed:0.251 green:0.000
> blue:0.502 alpha:1],
>   NSKernAttributeName:[NSNull
> null]}];
>
> NSString* blurb = s2;
> NSMutableAttributedString* content2 = [[NSMutableAttributedString
> alloc]
>initWithString:blurb
>
> attributes:@{NSFontAttributeName:[UIFont
> fontWithName:@"Georgia" size:14],
>NSKernAttributeName:[NSNull
> null]}];
> [content appendAttributedString:content2];
>
> // additional code will go here
>
> self.lab.attributedText = content;
>
> It works fine; I see the title and the paragraph. Now, you see where it
> says "additional code will go here"? In that spot, I add paragraph styles
> to my attributed string, like this:
>
> NSMutableParagraphStyle* para = [NSMutableParagraphStyle new];
> para.headIndent = 10;
> para.firstLineHeadIndent = 10;
> para.paragraphSpacingBefore = 5;
> para.tailIndent = -1;
> para.lineBreakMode = NSLineBreakByWordWrapping;
> [content addAttribute:NSParagraphStyleAttributeName value:para
> range:NSMakeRange(0,title.length)];
>
> para = [NSMutableParagraphStyle new];
> para.headIndent = 10;
> para.firstLineHeadIndent = 10;
> para.tailIndent = -1;
> para.lineBreakMode = NSLineBreakByTruncatingTail;
> para.paragraphSpacing = 5;
> [content addAttribute:NSParagraphStyleAttributeName value:para
> range:NSMakeRange(title.length,1)];
>
> NSStringDrawingContext* con = [NSStringDrawingContext new];
> CGRect r = [content boundingRectWithSize:CGSizeMake(280,1)
> options:NSStringDrawingUsesLineFragmentOrigin context:con];
> NSLog(@"%f", r.size.height);
>
> The result (and this is the problem) is that the label truncates after the
> **first line** of the second paragraph ("Four score and seven years ago,
> our fa…"). Why? There's plenty of room in my label for more lines!
>
> Moreover, I am trying to predict the height that my text will occupy.
> Right now I'm just logging the result, as shown above. Without those
> paragraph styles, I get 121, which looks right. With the paragraph styles,
> I get 53, which suggests that the truncation is taking place here too!
>
> Now, I know that I can fix the problem by changing
> NSLineBreakByTruncatingTail to NSLineBreakByWordWrapping for the second
> paragraph. But I don't want to! Because if in fact the text is too long for
> the height of the actual label, I do want ellipses at the end!
>
> So how can I get tail truncation **when the label is too short**, without
> getting **unnecessary** truncation after the first line of the second
> paragraph?
>
> Thx - m.
>
> --
> matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/himself%40sfko.com
>
> This email sent to hims...@sfko.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the 

Re: iOS kiosk mode?

2012-11-05 Thread Sixten Otto
On Sun, Nov 4, 2012 at 12:25 AM, Rick Mann  wrote:
> Ah, interesting! Still doesn't go quite as far as I want Apple to go: I want 
> a power-cycled device to skip Springboard and launch my app. I want the 
> watchdog to kill and restart my app.
>

Check out the Lock to App feature available with iOS 6 through the
Apple Configurator app. Sounds to me like exactly what you're after.
https://itunes.apple.com/us/app/apple-configurator/id434433123?mt=12
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Formatting a set of NSDecimalNumber values

2012-08-10 Thread Sixten Otto
On Fri, Aug 10, 2012 at 10:46 AM, Kyle Sluder  wrote:
> Don't forget bout languages where numbers read right-to-left.

Like which? (I had, shamefully, completely forgotten r-t-l text in
this scheme. But some casual googling leads me to believe that Hebrew
and Arabic, at least, write numbers in big-endian form like English.)

And while we're poking holes in this idea of mine, are there any iOS
localizations that use non-Arabic numerals? :-)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Formatting a set of NSDecimalNumber values

2012-08-10 Thread Sixten Otto
I'm definitely aware of the font issues, and those I can deal with (I
think?). In particular, if I can line up the decimal separators
vertically, everything else should align, as I should be able to force
a font that has lining figures.

My reasoning for measuring the strings in a fixed locale with a
specific format string was specifically to eliminate the issues of
localization: have a known decimal separator and nothing else but
digits, so that counting the characters doesn't have to account for
thousands separators, etc.

I could, as you say, measure the drawn sizes of the localized strings.
I guess my resistance to that idea is really that I'd have to do it a
couple of times (the width of the whole string, and the position of
the decimal separator), and that it seems likely to be really slow.

On Fri, Aug 10, 2012 at 9:29 AM, Jens Alfke  wrote:
>
> On Aug 10, 2012, at 8:58 AM, Sixten Otto  wrote:
>
> In order to make the columns line up, and to know how much space I'll
> need, what I'd like to do is to figure out, for each set of numbers,
> the width of the format I'll need. In other words, the maximum number
> of integer places, and the maximum number of fractional places.
>
>
> Just to make things even more complicated: you're assuming digits are
> monospaced. In many fonts they are not — it generally looks better if a 1 is
> narrower than a 0, for instance. The "." is also pretty much guaranteed to
> be a lot narrower than a digit, and the "e" in scientific notation will be a
> different width too.
>
> There's also the matter that number formatting is localizable. Many
> countries use "," for a decimal point.
>
> One workaround might be to convert each number to a string in the
> POSIX locale, and then measure its length and the position of the
> decimal point.
>
>
> That doesn't seem like a workaround, it seems like the correct solution
> (although why not use the user's real locale?). Fundamentally you are trying
> to display and align character strings, so you have to treat the numbers as
> strings when computing their alignment. For best results use AppKit (or
> UIKit?) methods to compute the pixel width of each string in the font you're
> using.
>
> —Jens

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Formatting a set of NSDecimalNumber values

2012-08-10 Thread Sixten Otto
I'm working on an app where I need to take several sets of numeric
values (currently stored as NSDecimalNumber), and display them in
columns. Each set will have approximately the same magnitude, but the
magnitude of each set may change, and I won't know ahead of time what
they are. So one might be values like (1.23, 2.3, 1.567), and another
(1234.1, 2345, 1999.4).

In order to make the columns line up, and to know how much space I'll
need, what I'd like to do is to figure out, for each set of numbers,
the width of the format I'll need. In other words, the maximum number
of integer places, and the maximum number of fractional places. For
the examples above: 1 and 3 in the first case, 4 and 1 in the second.

Now, the NSDecimal representation would answer this directly, by
combining the length of the mantissa and the value of the exponent.
The problem is, the fields of that structure are explicitly private,
and there doesn't appear to be any API to get the values of the
mantissa and exponent out of it.

One workaround might be to convert each number to a string in the
POSIX locale, and then measure its length and the position of the
decimal point. But that seems like a very long way around. And I'm
shamefully sketchy on my C math, but I'd guess that there's a route to
the answer there, also (possibly with some loss of precision?).

What's the simplest and/or most efficient way of deriving this information?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Forcing Core Data to save attribute changed behind its back?

2012-07-24 Thread Sixten Otto
On Tue, Jul 24, 2012 at 11:27 AM, Sean McBride  wrote:
> Yes.  My object is a subclass of NSObject and I don't override isEqual:.  As 
> I test, I overrode it and always return NO.  At first, I thought this did the 
> trick, since Core Data passed through this and saved properly; but alas, it 
> only seems to go through the path once after the document is opened, not 
> every time I ask it to save.

Are you still also triggering the KVO notices and/or using the setter?

My thinking was that you probably need both things: first, to take an
action that causes Core Data to notice you're changing the value (like
calling -will/didChangeValueForKeyPath:), and second, that when Core
Data compares the before and after values, that they are not -isEqual:
to one another.

(But, to be clear, this is untested supposition on my part.)

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Forcing Core Data to save attribute changed behind its back?

2012-07-24 Thread Sixten Otto
On Mon, Jul 23, 2012 at 3:03 PM, Sean McBride  wrote:
> when I change it, instead of the usual setAttribute:newValue I mutate the 
> object directly.
>  - will/didChangeValueForKeyPath: but that's not a sufficient 'kick'

Out of random curiousity, does this big mutable object you're updating
change in a way Core Data would see? Does the object's "before" state
-isEqual: its "after" state?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Tab Bar Item naming convention?

2012-07-09 Thread Sixten Otto
On Thu, Jul 5, 2012 at 10:31 PM, Laurent Daudelin
 wrote:
> But, do I follow the same naming convention as for the app icon by adding a 
> "@2x" to the file name?

Absolutely. That's a general convention for naming hidpi resources.

https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreens/SupportingHiResScreens.html#//apple_ref/doc/uid/TP40010156-CH15-SW8
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Index in only one section of UITableView

2011-11-30 Thread Sixten Otto
On Wed, Nov 30, 2011 at 7:59 PM, James West  wrote:
> Is it possible to override the default behavior of the UITableView index so 
> it only shows over the right side of a subsection of a table - scrolling with 
> it, etc?

Yeah, that really isn't how the index works at all (even leaving out
the part where the index points to sections, and not to individual
cells). You're gonna have to roll your own thing.

One thought that occurs to me, but probably isn't a terribly good
idea: make your index a subview of a custom section header (and make
sure that that header has clipsToBounds turned off). Then it'll scroll
with the table, and maybe(?) stay pinned in view when the table floats
the section header at the top. You can ask the table for its bounds,
and for the bounding rect of the section, in order to lay out that
custom index appropriately.

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Storyboard scene and UIViewController

2011-11-03 Thread Sixten Otto
On Thu, Nov 3, 2011 at 12:40 PM, Eric E. Dolecki  wrote:
> Then in my code:
>
> UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
> @"MainStoryboard" bundle:[NSBundle mainBundle]];
> HomeUIViewController *hv = [storyboard
> instantiateViewControllerWithIdentifier:@"deanna"];
> [splitViewController presentModalViewController:hv animated:NO];

Just out of general paranoia, have you checked that hv is getting a
non-nil value?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data Xcode 4 question

2011-09-01 Thread Sixten Otto
On Thu, Sep 1, 2011 at 2:56 PM, Andrew Kinnie  wrote:
> Last I looked at mogenerator, it didn't support Xcode 4.

mogenerator supports Xcode 4 just fine (it's the command-line tool).
It's Xmo'd (the Xcode plugin) that no longer works. So, you need to
regenerate the code manually when you change the model, but the tool
still does most of the work for you.

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Strange NSFileManager file replacement issue

2011-08-19 Thread Sixten Otto
On Fri, Aug 19, 2011 at 1:14 PM, Steve Christensen  wrote:

> Is there any reason why you can't put the downloaded file in your app's
> private cache directory (...//Library/Caches), i.e., what gets
> returned by NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
> NSUserDomainMask, YES)? That should certainly be within the bigger app
> directory hierarchy, and thus a peer of the app's Documents directory.
>

Can't? No. My preference for NSTemporaryDirectory() was mainly the notion
that I had help from the OS in clearing out any old partial downloads that
whatever weird circumstances might have orphaned.

But I'm not sure that it'd matter. Even when I moved the file from there to
the NSItemReplacementDirectory given by the file manager,
-replaceItemAtURL:... was still behaving identically. (See my previous
message for the details.)

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Strange NSFileManager file replacement issue

2011-08-19 Thread Sixten Otto
On Thu, Aug 18, 2011 at 10:14 PM, Quincey Morris
 wrote:
> c. Can you show us the actual line of code that does the replacement?

Here's the original code (plus the addition of an assert on the file
manager). The property self.filePath has the path to the current
version of the file that's already on disk (from a previous pass
through this code). In my current test case, the paths look something
like:

self.filePath: 
/Users/sixten/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/840B5926-8107-458E-87ED-ABF0F084BC12/Documents/Subdir/MyFile.pdf
tempFilePath: /var/folders/KP/KPl-d+TMHGaIJ6QIjMYNQTI/-Tmp-/2212

// start original code
NSFileManager* fileManager = [[NSFileManager alloc] init];
NSAssert(fileManager != nil, @"File manager wasn't created.");

NSString* directoryPath = [fileManager
rd_documentsSubdirectory:self.document.volume];
BOOL isDirectory;
NSAssert1([fileManager fileExistsAtPath:tempFilePath
isDirectory:&isDirectory] && isDirectory == NO, @"Bad temp file path
%@", tempFilePath);
NSAssert1([fileManager fileExistsAtPath:directoryPath
isDirectory:&isDirectory] && isDirectory == YES, @"Bad document
directory %@", directoryPath);

if( [desiredName length] == 0 ) {
  if( self.filePath ) {
desiredName = [self.filePath lastPathComponent];
  }
  else {
desiredName = [tempFilePath lastPathComponent];
  }
}

NSString* finalPath = [directoryPath
stringByAppendingPathComponent:desiredName];
NSError* error = nil;
if( [finalPath isEqualToString:self.filePath] || [self.filePath
hasPrefix:directoryPath] ) {
  NSURL* existingFileURL = [NSURL fileURLWithPath:finalPath];
  NSURL* newFileURL = [NSURL fileURLWithPath:tempFilePath];
  NSString* backupItemName = [NSString
stringWithFormat:@"__%@__.bak", self.documentId];
  NSURL* resultURL = nil;

  // *** 1
  if( [fileManager replaceItemAtURL:existingFileURL
withItemAtURL:newFileURL backupItemName:backupItemName options:0
resultingItemURL:&resultURL error:&error] ) {
self.filePath = [resultURL path];
success = YES;
  }
  else {
// *** ends up here, with no error == nil
LOG_GENERAL(LOG_PRIORITY_HIGHEST, @"Error attempting to
replace »%@« with »%@«: %@\n%@", tempFilePath, finalPath, [error
localizedDescription]);
NSAssert(NO, @"Couldn't move file to designated location");
  }
  // *** 2
}
else {
  // ... move the temp file to finalPath, which works just fine,
and update self.filePath
}

[fileManager release];
// end original code


This morning, I replaced the code between the "*** 1" and "*** 2" with
the following, which still failed in exactly the same way. It does get
create a replacement directory and return it, my temp file moves into
that directory without issue, but the swap still mysteriously fails.
The value of swapURL looks like:

file://localhost/Users/sixten/Library/Application%20Support/iPhone%20Simulator/4.3.2/Applications/840B5926-8107-458E-87ED-ABF0F084BC12/Documents/Subdir/(A%20Document%20Being%20Saved%20By%20MyApp)/MyFile.pdf

  // *** 1
  NSURL* swapURL = [fileManager
URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask
appropriateForURL:existingFileURL create:YES error:&error];
  if( swapURL ) {
swapURL = [swapURL URLByAppendingPathComponent:desiredName];
if( [fileManager moveItemAtURL:newFileURL toURL:swapURL error:NULL] ) {
  if( [fileManager replaceItemAtURL:existingFileURL
withItemAtURL:swapURL backupItemName:backupItemName options:0
resultingItemURL:&resultURL error:&error] ) {
self.filePath = [resultURL path];
success = YES;
  }
  else {
// *** still gets here, with no error set!
LOG_GENERAL(LOG_PRIORITY_HIGHEST, @"Error attempting to
replace »%@« with »%@«: %@\n%@", tempFilePath, finalPath, [error
localizedDescription]);
NSAssert(NO, @"Couldn't move file to designated location");
  }
}
  }
  else {
LOG_GENERAL(LOG_PRIORITY_HIGHEST, @"Error attempting to
replace »%@« with »%@«: %@\n%@", tempFilePath, finalPath, [error
localizedDescription]);
NSAssert(NO, @"Couldn't find/create swap location");
  }
  // *** 2
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Strange NSFileManager file replacement issue

2011-08-19 Thread Sixten Otto
On Thu, Aug 18, 2011 at 10:38 PM, Ken Thomases  wrote:

> My thinking is that -replaceItemAtURL:... is a wrapper around
> exchangedata() or FSExchangeObjects().  Those functions, and the general
> operation that they perform, require that the files to be exchanged be on
> the same file system.  It would seem that, on iOS, the application's
> Document folder is on a different file system from the temporary directory.
>  This is exactly the problem which
> -URLForDirectory:NSItemReplacementDirectory... is intended to solve.  It's
> to give you a temporary directory that's appropriate for a subsequent
> -replaceItemAtURL:... call.
>

If true, that certainly makes that method far less useful in the general
case than I expected, and really seems restricted to the "saving a new copy
of an in-memory document and swapping it" case. I really don't want to put
the in-process download into the Documents tree. (Both because it's
potentially visible to the user through iTunes, and because
NSTemporaryDirectory() will be swept up occasionally.) I'll see what I can
do to test this this morning.

I guess the question then becomes:
- Abandon the use of the atomic swap altogether, and roll my own
copy+remove?
- Or introduce an extra step, where I copy the temp file into
NSItemReplacementDirectory,
and then call replaceItemAtURL?
- Or is there some better pattern altogether?


> I recommend that you file bugs against the documentation for not adequately
> explaining the requirements on the newItemURL parameter and against the
> implementation for failing to provide a valid NSError pointer on failure in
> this case.
>

Definitely. I want to verify that I *can* make it work if the replacement
item is already in the Documents tree / replacement directory, and then I'll
be spending some time on the bug reporter.

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Strange NSFileManager file replacement issue

2011-08-19 Thread Sixten Otto
On Thu, Aug 18, 2011 at 10:14 PM, Quincey Morris <
quinceymor...@rivergatesoftware.com> wrote:

> a. What version of iOS did this fail on?
>

The 4.3 simulator (running on Snow Leopard, Xcode 4.0.2).


> b. Can you assert that the receiver of the 'replace…' method is not nil?
> (If it was nil, the method call would behave exactly as you describe.)
>

Good thing to check, but since it's returning YES for the -fileExistsAtPath:
calls, and works in some of the other cases, I doubt that the NSFileManager
is nil.


> c. Can you show us the actual line of code that does the replacement?
>

I'll post my code when I get in to the office. (I got about this far before
I had to leave last night.)

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Strange NSFileManager file replacement issue

2011-08-18 Thread Sixten Otto
I have an iOS app where I'm storing files in the app's Documents directory,
and occasionally downloading new versions from the server to replace them.
The actual code is split across a number of files and classes, but the end
of the process goes like this:

- The download of the new data to a temporary file in NSTemporaryDirectory()
finishes successfully.
- I calculate the path I want to copy it to.
- I see that there's already a previous version of the file at that path.
- I try to use -[NSFileManager
replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:]
to
swap in the new file.

That method returns NO for failure, so I check the error... but it's nil.
There's nothing there to tell me what the heck is failing. (In fact, when I
wasn't initializing my error pointer to nil, it was left as a garbage
pointer, and crashed my app.) My app put the original file there, so
(presumably) that path is writable. The file manager does return true from
-fileExistsAtPath: for both files.

The only thing that Google can turn up is this StackOverflow question. Same
exact symptoms. But, of course, no answers.
http://stackoverflow.com/questions/4899618/replaceitematurl-fails-without-error-on-ios-but-works-fine-on-osx

I can *remove* the file that I can't overwrite, and I can move the temp file
into Documents in the case where there isn't already a version on disk.
Obviously, neither of those cases uses replaceItemAtURL.

Does anyone know what circumstances might cause this failure? Any
recommendations on what things I should check next?

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Implementing async notifications

2010-12-10 Thread Sixten Otto
On Fri, Dec 10, 2010 at 2:50 PM, Jon Sigman  wrote:

> I have a Cocoa app that uses a dedicated thread to receive messages, and I
> would
> like that thread to post those messages as notifications so they can be
> processed asynchronously, outside my receiving loop (but not on the main
> thread).
>

Can you explain a little more about your reasons for using notifications?
Are you trying to publish the information about the incoming messages to
multiple specific things in your app?

It kind of reads to me like you're just trying to get the processing of the
messages out of the receiver thread, and into *some* other background
thread, which makes me think that maybe using a dispatch queue would be a
better solution. (Then you can let GCD handle all of the thread management.)


Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Call web service from iPhone [use soap]

2010-12-09 Thread Sixten Otto
On Thu, Dec 9, 2010 at 6:20 AM, ico  wrote:

> I want to develop an iPhone app which will consume a soap web service.
> I tried to use wsdl2objc (http://code.google.com/p/wsdl2objc/) to generate
> the Objective C stub codes, they can be compiled but it does not work.
>

You say that it doesn't work. In what way? You're not seeing a request come
in to the server? You're not getting the result you expected? Your program
is crashing?


> NSLog(@"Header:\n%@", calcRes.headers);
> NSLog(@"Body:\n%@", calcRes.bodyParts);
>
> The result is:
>
> *Header:*
>
> *(null)*
>
> *Body:*
>
> *(*
>
> *""*
>
> *)*
>

Knowing nothing about this service, or wsdl2objc, but having some experience
with SOAP services (and calling them from non-.NET languages), this seems
perfectly reasonable to me. You called the service, you got back a response,
and it has no headers, and a single response element in the body. The name
of the class for the instance in that bodyParts array matches what I'd
expect from the name of the service.

Of course, you'd need to examine that CalcService_AddIntegerResponse to see
whether the service really returned what you expected. But I'm not sure that
I see what the problem is.

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Help tracking down a dangling pointer?

2010-06-10 Thread Sixten Otto
On Thu, Jun 10, 2010 at 1:41 PM, Greg Parker  wrote:
> If you suspect a use-after-free bug somewhere, and NSZombie doesn't find it, 
> then try this:
> 1. Verify that NSZombie is operating. Add `NSMutableString alloc] init] 
> release] release]` to your code. Make sure NSZombie catches it.

Well, the simple test works: adding a deliberate over-release to my
applicationDidFinishLaunching: logs exactly the console message I'd
expect. And with a breakpoint on objc_exception_throw(), stops right
there.

With the actual crash, I get the stack trace I posted before, and no
expected console log. (I also tried turning the scribble off, and
disabling the breakpoint, just to see.)

> 2. If NSZombie doesn't help, try Guard Malloc. It's slow, but catches errors 
> that NSZombie does not catch.

Enabline Guard Malloc and running the app, it crashes in exactly the
same way, but the stack trace has slightly more information; the ?? is
replaced with an actual method (but still in framework code):
   #0  0x91a27ed7 in objc_msgSend
   #1  0x04ba6b20 in -[_PFManagedObjectReferenceQueue
_processReferenceQueue]
   #2  0x01dc89ba in _performRunLoopAction

(Just for grins, I turned off zombies and malloc logging, and tried
again, and got the same result.)

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Help tracking down a dangling pointer?

2010-06-10 Thread Sixten Otto
There are many, many questions and articles and discussions out there
about tracking down memory leaks, and finding over-release bugs.
Neither of those, AFAICT, is what's happening to me. If there's a good
article or Fine Manual out there that I should read, I haven't found
it.

In my iPhone app, I've got a modal table view controller that allows
users to manage a collection of Core Data entities. The immediate
symptom that I'm seeing is that you delete the last thing out of that
collection, and when you dismiss the controller, the app crashes with
EXC_BAD_ACCESS... but not in my code.

Here's the concrete information I have:

- The stack trace for the crash is as follows (which, of course, is
enormously frustrating, because it isn't happening in my code):
#0  0x91a27ed7 in objc_msgSend
#1  0x04ba6b20 in ??
#2  0x01dc89ba in _performRunLoopAction
#3  0x02240252 in __CFRunLoopDoObservers
#4  0x0223f65f in CFRunLoopRunSpecific
#5  0x0223ec48 in CFRunLoopRunInMode
#6  0x0288b615 in GSEventRunModal
#7  0x0288b6da in GSEventRun
#8  0x004b1faf in UIApplicationMain
#9  0x284a in main at main.m:14

- Examining $eax and $ecx (thanks, Greg Parker), the crash appears to
be happening when something calls -retainCount on the deleted managed
object instance.

- I've enabled zombies, and turned on several of the malloc debugging
flags. I've checked malloc_history, and the allocation of the object
is exactly where I expect, and the deallocation seems to be in a
reasonable place. (In particular, when the table view is autoreleased,
releasing its cells, one of which was holding a reference to the
entity.) The memory for the object IS being scribbled as expected.

- Build & Analyze doesn't turn anything up.

- I did some poking around with my limited GDB skills, and was able to
determine that, at the time of the crash, the managed object context
that had contained the instance was now empty. (As expected, given
that the object was deallocated.)

It seems like what's happening is that there's some object someplace
that's holding an unretained pointer to my entity, and trying to use
it after it's gone. But the stack trace doesn't tell me much of
anything (and I confess that I really don't grok assembly).

I'm hoping that maybe the trace will look familiar to someone on this
list, or someone might be able to recommend a technique for tracking
down what thing might have that pointer. I've found LOTS of advice for
determining what code freed an object, but nothing about groping
memory to find references to it.

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Writing an NNTP client

2010-06-01 Thread Sixten Otto
On Tue, Jun 1, 2010 at 9:57 AM, Uli Kusterer
 wrote:
>  I think there are also some open source NNTP clients out there
> (Newswatcher for example, but I don't know what license it's under

When I was poking around fairly recently, it appeared that most of the
Open Source apps for Mac were, in fact, wrapping C code from
Newswatcher, or maybe TIN. That certainly works, but no one should be
expecting to stumble across an elegant Objective-C library for NNTP.
(Attempting to write one of those is always one of those projects I
promise myself I'm going to try to tackle some day, and never do.)

Newswatcher itself is not Open Source (the source code was available,
but was owned by Northwestern; if memory serves, there was also a
non-commercial use clause attached to the source). There are slightly
more modern versions of the app in the form of MT-NewsWatcher,
NewsWatcher-X, and a few others.

> Panic's Unison is probably a surprisingly modern NNTP codebase.

Yeah, I would tend to agree with this. Whether they'd be willing to
license it out... Well, it'd be worth asking them!

As far as rolling one's own with sockets goes, I'll also plug
AsycSockets here as a somewhat higher-level API than BSD / CFSocket:
  http://code.google.com/p/cocoaasyncsocket/

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: POST request on iPhone

2010-06-01 Thread Sixten Otto
On Tue, Jun 1, 2010 at 6:03 AM, Joshua Tucker
 wrote:
> has anyone got any sample code for a POST request for interfacing with an API 
> such as the DirectAdmin API?

I believe the usual StackOverflow answer is to consider
ASIHTTPRequest, which gives a somewhat higher-level API than
NSURLConnection, built atop CFNetwork.
  http://allseeing-i.com/ASIHTTPRequest/

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Getting TextEdit to Recognise UTF-8 Output

2010-05-21 Thread Sixten Otto
On Fri, May 21, 2010 at 3:42 PM, K.Darcy Otto  wrote:
> I've tried prefacing the text file with a BOM in this way:

You may well already know this, and that may be something you're
attempting out of desperation, but:

"The endian order entry for UTF-8 in Table 2-4 is marked N/A because
UTF-8 code units
are 8 bits in size, and the usual machine issues of endian order for
larger code units do not
apply. The serialized order of the bytes must not depart from the
order defined by the UTF-
8 encoding form. Use of a BOM is neither required nor recommended for
UTF-8, but may
be encountered in contexts where UTF-8 data is converted from other
encoding forms that
use a BOM or where the BOM is used as a UTF-8 signature. See the “Byte
Order Mark”
subsection in Section 16.8, Specials, for more information."

http://www.unicode.org/versions/Unicode5.0.0/ch02.pdf, p36
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CCHmacInit - key?

2010-05-10 Thread Sixten Otto
On Mon, May 10, 2010 at 12:28 PM, Patrick M. Rutkowski
 wrote:
> I'm really not getting what the "key" argument to CCHmacInit() is
> supposed to be. I'm trying to implement oauth linked-in integration,

Not really an answer to your question, but are you trying to implement
OAuth from scratch? Is there a reason why you'd choose to do that over
known-working code like http://code.google.com/p/oauth/ ?

For that matter, if it's LinkedIn you're after, might I humbly suggest
http://github.com/ResultsDirect/LinkedIn-iPhone ? (It's not a whole
solution yet, but should save you some time getting started. And the
engine part shouldn't be iPhone-dependent.)

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Floating window on iPhone OS?

2010-04-28 Thread Sixten Otto
On Wed, Apr 28, 2010 at 6:11 PM, Laurent Daudelin
 wrote:
> I've seen in a few apps a little rounded corners status window appearing 
> [snip]
> Anybody knows how to do that?

http://github.com/jdg/MBProgressHUD ?

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSXML and invalid UTF8 characters

2010-01-28 Thread Sixten Otto
On Thu, Jan 28, 2010 at 6:16 PM, Keith Blount  wrote:
> I am using the NSXML classes to generate and parse my own XML files. 
> Sometimes these files store strings of text that has been brought in from 
> other applications (for instance, there might be a plain text representation 
> of some text the user has pasted in from Word).

For what it's worth, another common cause of problems with stuff
pasted from Word (at least on the web), is Word docs that contain
characters from the Windows-1252 character set that are invalid UTF-8
byte sequences. Most commonly, 0x80-0x9F, which is the range where
Windows-1252 differs from ISO-Latin-1.

So whatever solution you come up with to deal with the characters
0x00-0x1F that XML specifically doesn't allow, you probably want to
also account for ranges like 0x80-0xFF that aren't valid UTF-8 at all.

http://en.wikipedia.org/wiki/UTF-8#Invalid_byte_sequences
http://en.wikipedia.org/wiki/Windows-1252

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSDictionary trouble

2010-01-19 Thread Sixten Otto
On Tue, Jan 19, 2010 at 1:24 PM, Jens Alfke  wrote:
> On Jan 19, 2010, at 8:53 AM, Shawn Rutledge wrote:
>> I didn't try CFDictionary yet; is that appropriate for an iPhone app?
>
> But try NSMapTable first. It's sort of halfway between the two — it's an
> Objective-C class but it has greater flexibility in what it can store and
> how it stores it.

Is NSMapTable available in Cocoa Touch? I was under the impression
that that was Mac-only.

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: function/library to pack javascript?

2010-01-18 Thread Sixten Otto
On Mon, Jan 18, 2010 at 3:17 AM, Eric Boo  wrote:
> I'm trying to find a C/Objective-C function or library that will help me
> pack javascript, something like YUI Compressor or Dean Edwards's packer.

It may not be as aggressive as you'd like, but Doug Crockford's jsmin
has C source code available:
http://www.crockford.com/javascript/jsmin.html
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Architecture for concurrent network client

2009-09-21 Thread Sixten Otto
On Mon, Sep 21, 2009 at 4:58 PM, Jens Alfke  wrote:
>> connections available to the application. Somehow I need to track
>> which/how many connections are idle, and dequeue requests to those
>> connections.
>
> Just keep a mutable array of free connections.

As I think about it more, I think you may be right.

I think I got stuck thinking that access to this stuff was going to
need to be thread-safe, for some reason. (Maybe because I was worried
about overhead in initiating the download blocking the UI?) But if the
I/O handling is all asynchronous, then it's probably the case that the
access to the connection pool can all happen on the main thread:
- When the user adds a download request: if there are available
connections, dequeue one and give it the request; otherwise enqueue
the request.
- When a request completes: if there are queued requests, dequeue one
and give it to the connection; otherwise, enqueue the connection.

> Do you have control over the protocol used by the server?

No. And, in actual fact, it's NNTP, which is about as far from
"efficient" as you're gonna get. (I left that part out because I
didn't want to sidetrack too much into the I/O specifics.)

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: an app that never quits

2009-09-21 Thread Sixten Otto
On Mon, Sep 21, 2009 at 4:15 PM, Erick Calder  wrote:
> ok, perhaps there's another way I can solve my problem.  I have a little app
> called Trapster that uses something called "push technology"... I think what
> it means is that some server can send my app a signal and even though the
> app isn't running all the time, it gets woken up and responds to the
> message... can anyone point me to a howto?

The Push Notification Service Programming Guide is here:
  
http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html

Be advised, though, that push notifications are really directed at the
*user*. Yes, the alerts you can push provide a convenient way for the
user to start up your app (and your app is specifically informed of
that), but this isn't like waking up a daemon process on the device.
Your app can still only run in the foreground, and only at the
discretion of the user, and will still be quit when the user is done
with it. (Users can also turn off the push alerts entirely.)

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Architecture for concurrent network client

2009-09-21 Thread Sixten Otto
On Mon, Sep 21, 2009 at 12:20 PM, Jens Alfke  wrote:
> You don't need concurrency or threads to handle socket connections. The 'Mac
> way' is to use asynchronous I/O, hooking up the socket connections to the
> runloop and getting callbacks when data is available.

That's true, and I knew better than that. For the actual I/O part of
this, I'm definitely planning to let the system handle all of the
asynchronicity as you suggest. That seems to be pretty well-traveled
ground in terms of discussion and code libraries, so I'm hopeful I can
work that out on my own. :-)

I don't think that that gets me out of the problem I was really trying
to ask about, though, which is how to manage getting the work from the
(single) queue of requests from the user to the exactly N persistent
connections available to the application. Somehow I need to track
which/how many connections are idle, and dequeue requests to those
connections.

Sorry for muddying the waters!

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Architecture for concurrent network client

2009-09-21 Thread Sixten Otto
I'm trying to work out in my head the best way to structure a Cocoa
app that's essentially a concurrent download manager. There's a server
the app talks to, the user makes a big list of things to pull down,
and the app processes that list. (It's not using HTTP or FTP, so I
can't use the URL-loading system; I'll be talking across socket
connections.)

This is basically the classic producer-consumer pattern. The trick is
that the number of consumers is fixed, and they're persistent. The
server sets a strict limit on the number of simultaneous connections
that can be open (though usually at least two), and opening new
connections is expensive, so in an ideal world, the same N connections
are open for the lifetime of the app.

I've looked over the Apple's Concurrency Programming Guide
(http://developer.apple.com/mac/library/documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html),
and done some searching around on web and Stack Overflow, but not
finding a lot of information that seems directly applicable, because
of those constraints.

One way to approach this might be to create N threads, each of which
would "own" a connection, and wait on the request queue, blocking if
it's empty. Since the number of connections will never be huge, this
is not unreasonable in terms of actual system overhead. But
conceptually, it seems like Cocoa must offer a more elegant solution.

It seems like I could use an NSOperationQueue, and call
setMaxConcurrentOperationCount: with the number of connections. Then I
just toss the download requests into that queue. But I'm not sure, in
that case, how to manage the connections themselves. (Just put them on
a stack, and rely on the queue to ensure I don't over/under-run? Throw
in a dispatch semaphore along with the stack?)

I'd been thinking that Grand Central Dispatch might open up some other
ways of tackling this, but at first blush, it doesn't seem like it.
GCD's flagship ability to dynamically scale concurrency (mentioned,
for example, in Apple's guide's recommendations on Changing
Producer-Consumer Implementations) doesn't actually help me. But I've
just scratched the surface of reading about it.

Can anyone recommend other lines of inquiry? Or good examples of this
kind of concurrent operation?

Sixten
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com