Re: How to Launch an App using the Bundle ID?

2016-09-21 Thread Dave
Hi, Thanks a lot! I was surprised that NSWorkspace doesn’t include this seemingly useful method. All the Best Dave > On 20 Sep 2016, at 16:16, Charles Srstka wrote: > >> On Sep 20, 2016, at 5:48 AM, Dave > > wrote: >> >> Hi All, >> >> >> I’m using launchAp

Re: Passing param by reference then using within block throws exception

2016-09-21 Thread Steve Mills
On Sep 21, 2016, at 01:29:37, Jens Alfke wrote: > > I think the real problem is that the -enumerateObjectsUsingBlock: method has > an autorelease pool. If your real code is assigning something other than a > string constant to *fillMeIn, that string will probably get dealloced when > the autor

Re: Passing param by reference then using within block throws exception

2016-09-21 Thread Alex Zavatone
Stab in the dark here, but I'm stabbing blank. Is there an Instruments tool or debugging option to detect this? On Sep 21, 2016, at 7:53 AM, Steve Mills wrote: > On Sep 21, 2016, at 01:29:37, Jens Alfke wrote: >> >> I think the real problem is that the -enumerateObjectsUsingBlock: method ha

Re: Passing param by reference then using within block throws exception

2016-09-21 Thread Steve Mills
On Sep 21, 2016, at 08:53 AM, Alex Zavatone wrote: Stab in the dark here, but I'm stabbing blank. Is there an Instruments tool or debugging option to detect this? Thanks for getting stabby. Fourvel appreciates it (only relevant if you're a CBB fan). It doesn't appear that anything will detec

Re: Conditionally declaring a BOOL in a .m file to be accessed in a .c function

2016-09-21 Thread Alex Zavatone
OK. So how do I change that bool within a method in that .m file as the result of a condition? Thanks. Sent from my iPad. Please pardon typos. On Sep 20, 2016, at 11:58 AM, Ryan Dignard wrote: > This doesn't work? > in the .m file at file scope > BOOL condition = NO; > > in the .c file at f

Re: Conditionally declaring a BOOL in a .m file to be accessed in a .c function

2016-09-21 Thread Alex Zavatone
Unknown type. But bool works. Thanks, Ryan. Sent from my iPad. Please pardon typos. On Sep 20, 2016, at 11:58 AM, Ryan Dignard wrote: > This doesn't work? > in the .m file at file scope > BOOL condition = NO; > > in the .c file at file scope > extern BOOL condition; > > On Tue, Sep 20, 20

Re: Conditionally declaring a BOOL in a .m file to be accessed in a .c function

2016-09-21 Thread Alex Zavatone
Please ignore those last two messages. An offline device just came on and those were sent last night. Thanks. On Sep 20, 2016, at 11:04 PM, Alex Zavatone wrote: > Unknown type. But bool works. > > Thanks, Ryan. ___ Cocoa-dev mailing list (Co

How to update UI from a background thread

2016-09-21 Thread Dave
Hi All, How can I update my UI from a background thread? I have a method that does a LOT of intense processing, it calls a delegate method in my Window Controller which appends it to a Logging Scroll View, however nothing shows up in the Scroll View although it NSLog’s the string ok. Firstly i

Re: How to update UI from a background thread

2016-09-21 Thread Sandor Szatmari
In general, one simple form is: dispatch_async( dispatch_get_main_queue(), ^{ // do UI updates on the main thread. }); This can also be done with NSOperationQueue: [[NSOperationQueue mainQueue] addOperationWithBlock:^{ // do UI updates on main thread. }]; Sandor Szatmari > On Sep 21, 2016, at

Re: How to update UI from a background thread

2016-09-21 Thread Dave
Hi, This doesn’t work probably because the Class is that is calling back the delegate method that updates the Scroll View is also being run on the main thread. Sorry I should have said this earlier. I tried updating the UI on a background thread and it seemed to work BUT I got warning message f

Re: How to update UI from a background thread

2016-09-21 Thread Quincey Morris
On Sep 21, 2016, at 09:20 , Dave wrote: > > The time consuming method I am calling is in a third party library and it > must be called in the main thread. You cannot update UI on a background thread, so if the library method is blocking the main thread you’re out of luck. The only solution is

Re: How to update UI from a background thread

2016-09-21 Thread Jens Alfke
> On Sep 21, 2016, at 8:40 AM, Dave wrote: > > How can I update my UI from a background thread? You can’t literally do that. But you can schedule code to run on the main thread, and update the UI in that code. Use dispatch_async to schedule the UI-related code on the main thread/queue. Or if

Re: How to update UI from a background thread

2016-09-21 Thread Doug Hill
> On Sep 21, 2016, at 10:00 AM, Quincey Morris > wrote: > > On Sep 21, 2016, at 09:20 , Dave wrote: >> >> The time consuming method I am calling is in a third party library and it >> must be called in the main thread. > > You cannot update UI on a background thread, so if the library metho

Re: How to update UI from a background thread

2016-09-21 Thread David Hoerl
> How can I update my UI from a background thread? > > I have a method that does a LOT of intense processing, it calls a delegate method in my Window Controller which appends it to a Logging Scroll View, however nothing shows up in the Scroll View although it NSLog’s the string ok. --- There

Re: How to update UI from a background thread

2016-09-21 Thread Jens Alfke
> On Sep 21, 2016, at 10:13 AM, Doug Hill wrote: > > The symptoms you mention sound like a classic deadlock problem. That is, a > code block running on the main queue schedules another code block on the main > queue, but the original block never completes thus causing the app to hang or > the

CALayer kCAGravityResizeAspectFill and kCAGravityTop

2016-09-21 Thread Torsten Curdt
On iOS I want to fill a layer with an image. The width should be filled and the image should retain its aspect ratio. This layer.contents = image.cgImage layer.contentsGravity = kCAGravityResizeAspectFill almost does the right thing - but it positions the image at the centers. I w

Re: CALayer kCAGravityResizeAspectFill and kCAGravityTop

2016-09-21 Thread David Duncan
> On Sep 21, 2016, at 11:18 AM, Torsten Curdt wrote: > > On iOS I want to fill a layer with an image. > The width should be filled and the image should retain its aspect ratio. > This > >layer.contents = image.cgImage >layer.contentsGravity = kCAGravityResizeAspectFill > > almo

Re: CALayer kCAGravityResizeAspectFill and kCAGravityTop

2016-09-21 Thread Torsten Curdt
> > There isn’t an option to fill width and align top. The more general > recommendation in this space however would be to use a UIImageView, which > has all the same options but participates in higher level layout (including > the content of autoResizingMasks, and also auto layout). > I am using

Re: CALayer kCAGravityResizeAspectFill and kCAGravityTop

2016-09-21 Thread David Duncan
> On Sep 21, 2016, at 11:44 AM, Torsten Curdt wrote: > > There isn’t an option to fill width and align top. The more general > recommendation in this space however would be to use a UIImageView, which has > all the same options but participates in higher level layout (including the > content

MLMediaLibrary sometimes does not call my KVO

2016-09-21 Thread Gabriel Zachmann
I am a bit at a loss about the MLMediaLibrary API. Maybe, I haven't quite understood it yet, maybe something else is wrong. I am writing a screen saver that accesses Photos' albums and the images referenced by them. (Code excerpts follow at the end of this email.) I create an array of the top le

Re: MLMediaLibrary sometimes does not call my KVO

2016-09-21 Thread Graham Cox
> On 22 Sep 2016, at 8:59 AM, Gabriel Zachmann wrote: > > I am a bit at a loss about the MLMediaLibrary API. > Maybe, I haven't quite understood it yet, maybe something else is wrong. > > I am writing a screen saver that accesses Photos' albums and the images > referenced by them. > (Code exce

Stupid objective-c question

2016-09-21 Thread Gabriel Zachmann
I've got a stupid, curious question regarding a code snippet that I have found on the net (I tried it, it works). Here is the code snippet: - (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) con

Re: Stupid objective-c question

2016-09-21 Thread Quincey Morris
On Sep 21, 2016, at 16:44 , Gabriel Zachmann wrote: > > how can the compiler know that '==' in this case is a NSString comparison? It can’t because it isn't. What’s being compared are raw pointers. The string value is irrelevant. > Or is some other magic going on here? if so, which? No magic,

Re: Stupid objective-c question

2016-09-21 Thread Steve Mills
> On Sep 21, 2016, at 18:44, Gabriel Zachmann wrote: > > I've got a stupid, curious question regarding a code snippet that I have > found on the net (I tried it, it works). > > Here is the code snippet: > > - (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object >

Re: Stupid objective-c question

2016-09-21 Thread Daniel Stenmark
It’s doing a pointer comparison while making poor assumptions about how the compiler will optimize the storage of string constants. This is bad; DO NOT DO THIS. Dan > On Sep 21, 2016, at 4:44 PM, Gabriel Zachmann wrote: > > I've got a stupid, curious question regarding a code snippet that I

Re: Stupid objective-c question

2016-09-21 Thread Graham Cox
> On 22 Sep 2016, at 9:44 AM, Gabriel Zachmann wrote: > > I have found on the net That isn’t always a recommendation ;) > if ( context == (__bridge void *) @"mediaLibraryLoaded" ) Don’t do this, even if it appears to work. You got lucky, or are taking advantage of undocumented implement

Re: Stupid objective-c question

2016-09-21 Thread Doug Hill
> On Sep 21, 2016, at 4:52 PM, Steve Mills wrote: > >> On Sep 21, 2016, at 18:44, Gabriel Zachmann wrote: >> >> I've got a stupid, curious question regarding a code snippet that I have >> found on the net (I tried it, it works). >> >> Here is the code snippet: >> >> - (void) observeValueFor

Re: Stupid objective-c question

2016-09-21 Thread Gabriel Zachmann
>> >> how can the compiler know that '==' in this case is a NSString comparison? > > It can’t because it isn't. What’s being compared are raw pointers. The string > value is irrelevant. Let me try to paraphrase, in order to check whether I am understanding correctly. Whenever I have two stri

Re: Stupid objective-c question

2016-09-21 Thread Jens Alfke
> On Sep 21, 2016, at 4:44 PM, Gabriel Zachmann wrote: > > My question is: how can the compiler know that '==' in this case is a > NSString comparison? It doesn’t. In Obj-C, “==“ is always a pointer comparison even if it’s applied to objects. It is NOT the same as -isEqual:. This idiom with

Re: Stupid objective-c question

2016-09-21 Thread Quincey Morris
On Sep 21, 2016, at 17:05 , Gabriel Zachmann wrote: > > In other words, the compiler unifies the two occurrences of the two literals, > thus effectively storing only one literal? Correct. > So what would be the proper way to do it? A global variable has a fixed, unique memory address, so you

Re: Stupid objective-c question

2016-09-21 Thread Slipp Douglas Thompson
> Whenever I have two string literals @"XYZ" at different places in the same > compilation unit, > and the XYZ are identical, then the compiler (or the Objective-C standard) > make sure that > the pointers to those literals are identical? > > In other words, the compiler unifies the two occurren

Re: Stupid objective-c question

2016-09-21 Thread Quincey Morris
On Sep 21, 2016, at 17:01 , Graham Cox wrote: > > This should be: if([(NSString*)context > isEqualToString:@“mediaLibraryLoaded”])… Actually, this is not a good idea either, because *other* observations — ones you don’t control — might use a value that’s not an object, or not even a valid poi

Re: Stupid objective-c question

2016-09-21 Thread Slipp Douglas Thompson
> On Sep 21, 2016, at 17:01 , Graham Cox wrote: >> >> This should be: if([(NSString*)context >> isEqualToString:@“mediaLibraryLoaded”])… > > Actually, this is not a good idea either, because *other* observations — ones > you don’t control — might use a value that’s not an object, or not even a

Re: Stupid objective-c question

2016-09-21 Thread Slipp Douglas Thompson
> On Sep 21, 2016, at 8:00 PM, Slipp Douglas Thompson > wrote: > >> On Sep 21, 2016, at 17:01 , Graham Cox wrote: >>> >>> This should be: if([(NSString*)context >>> isEqualToString:@“mediaLibraryLoaded”])… >> >> Actually, this is not a good idea either, because *other* observations — >> on

Re: Stupid objective-c question

2016-09-21 Thread Quincey Morris
On Sep 21, 2016, at 18:00 , Slipp Douglas Thompson wrote: > > isEqualToString: could cause issues here so isEqual: is the most sure-fire > solution Er, no. If the context is not an object, [context isEqual: … anything …] is going to crash in objc_msgSend before execution gets to the ‘isEqual’

Re: Stupid objective-c question

2016-09-21 Thread Graham Cox
> On 22 Sep 2016, at 10:40 AM, Quincey Morris > wrote: > > On Sep 21, 2016, at 17:01 , Graham Cox wrote: >> >> This should be: if([(NSString*)context >> isEqualToString:@“mediaLibraryLoaded”])… > > Actually, this is not a good idea either, because *other* observations — ones > you don’t co

Re: Stupid objective-c question

2016-09-21 Thread Doug Hill
> On Sep 21, 2016, at 6:36 PM, Graham Cox wrote: > > >> On 22 Sep 2016, at 10:40 AM, Quincey Morris >> wrote: >> >> On Sep 21, 2016, at 17:01 , Graham Cox wrote: >>> >>> This should be: if([(NSString*)context >>> isEqualToString:@“mediaLibraryLoaded”])… >> >> Actually, this is not a good

Re: Stupid objective-c question

2016-09-21 Thread Wim Lewis
On Sep 21, 2016, at 7:00 PM, Doug Hill wrote: > As to the context type, I would be interested to know of cases where the > observer doesn't have control over the context. My understanding is that the > context is something that the observer sets itself when calling addObserver, > and it is pass

Re: Stupid objective-c question

2016-09-21 Thread Quincey Morris
On Sep 21, 2016, at 19:00 , Doug Hill wrote: > > Just to be clear, the original question was specifically about comparing an > Objective-C string literal. For this case, you definitely want to use > -[NSString isEqualToString:] Actually, no. A couple of similar comments in this thread have sli

Re: Stupid objective-c question

2016-09-21 Thread Jens Alfke
> On Sep 21, 2016, at 6:36 PM, Graham Cox wrote: > > Which is yet another reason why void* is such a shitty concept. Apple could > easily have insisted that parameter was id without any real > problems, so void*… sheesh. It’s not an object! It’s just an opaque ‘cookie’ that you can use to rec

Re: Stupid objective-c question

2016-09-21 Thread Jens Alfke
> On Sep 21, 2016, at 7:00 PM, Doug Hill wrote: > > As to the context type, I would be interested to know of cases where the > observer doesn't have control over the context. My understanding is that the > context is something that the observer sets itself when calling addObserver, > and it i

Re: Stupid objective-c question

2016-09-21 Thread Doug Hill
> On Sep 21, 2016, at 8:33 PM, Quincey Morris > wrote: > > On Sep 21, 2016, at 19:00 , Doug Hill > wrote: >> >> Just to be clear, the original question was specifically about comparing an >> Objective-C string literal. For this case, you definitely want to use >>

Re: Stupid objective-c question

2016-09-21 Thread Jeff Evans
Whoa - maybe I've had too much wine with dinner, but: Is it really true what Jens says, that [[NSArray alloc]init] always returns the same pointer? If that is the case, how can one declare two separate arrays? Jeff On Sep 21, 2016, at 8:50 PM, Jens Alfke wrote: > On Sep 21, 2

Re: Stupid objective-c question

2016-09-21 Thread Doug Hill
I think it’s because an NSArray is immutable such that an empty array is guaranteed to never change. This gives the compiler opportunities for optimization based on this knowledge. It starts to get interesting when you do things like: NSArray *emptyArray = [[NSArray alloc] init]; NSArray *ano

Re: Stupid objective-c question

2016-09-21 Thread Jens Alfke
> On Sep 21, 2016, at 9:19 PM, Jeff Evans wrote: > > Is it really true what Jens says, that [[NSArray alloc]init] always > returns the same pointer? > If that is the case, how can one declare two separate arrays? NSArray is immutable, so any two empty NSArrays are equal/identical.

Re: Stupid objective-c question

2016-09-21 Thread Jeff Evans
Ah - yes, thank you. Of course, so [[NSArray alloc]init] is actually useless; I hadn't thought of that. No one would ever declare an array that way. One would have to init it with objects to be useful at all, and then it presumably would point to different data than another NSArray (even nonmuta

Re: Stupid objective-c question

2016-09-21 Thread Quincey Morris
On Sep 21, 2016, at 21:10 , Doug Hill wrote: > > I believe the original question was why you can compare a string literal to > another object pointer using the == operator and it somehow works. Actually, we’re more or less on the same page here, but for posterity… There’s no “somehow” with the

Re: Stupid objective-c question

2016-09-21 Thread Doug Hill
> On Sep 21, 2016, at 10:07 PM, Quincey Morris > wrote: > > On Sep 21, 2016, at 21:10 , Doug Hill > wrote: >> >> I believe the original question was why you can compare a string literal to >> another object pointer using the == operator and it somehow works. > >

Re: Stupid objective-c question

2016-09-21 Thread Jens Alfke
> On Sep 21, 2016, at 9:47 PM, Jeff Evans wrote: > > One would have to init it with objects to be useful at all, and then it > presumably would point to different data than another NSArray (even > nonmutable) inited with objects. Yup. Another fun fact is that the non-mutable classes all imple

Re: Stupid objective-c question

2016-09-21 Thread Quincey Morris
On Sep 21, 2016, at 21:47 , Jeff Evans wrote: > > Of course, so [[NSArray alloc]init] is actually useless; I hadn't thought of > that. No one would ever declare an array that way. Just continuing my nitpicking tour of this thread: It isn’t useless. Sometimes you really want an empty array. For