Re: Stupid objective-c question

2016-09-23 Thread Graham Cox

> On 24 Sep 2016, at 12:13 PM, Uli Kusterer  
> wrote:
> 
>> I expect the first thing -isEqualToString: does is a pointer comparison, so 
>> it’s unlikely to be significantly less performant for the case of when the 
>> pointers are literally identical.
> 
> No, Graham, don't do that!
> 
> There is no guarantee that the context is a valid object. It is just supposed 
> to be a unique pointer value so your class can tell a KVO notification from 
> notifications for other observers on the same object (e.g. if a subclass 
> observes the same value as a base class).


Yep, I’ve realised (from this discussion) that that’s an invalid assumption of 
another kind.

I’ve been revising code that does this as a result.

Always something to learn :)

—Graham



___

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: How to update UI from a background thread

2016-09-23 Thread Uli Kusterer
On 21 Sep 2016, at 18:20, Dave  wrote:
> 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 from 
> CALayer or maybe CATransaction and I think it caused the App to hang.

 You can do limited drawing into an existing view hierarchy on a secondary 
thread (that's how e.g. the throbbing default button in previous OS versions 
was drawn), but you have to do it in a very particular way.

Whatever you do, you mustn't manipulate the view hierarchy from a thread. All 
that'll do is screw up AppKit's or UIKit's internal data structures and lead to 
random crashes due to memory corruption.

> The time consuming method I am calling is in a third party library and it 
> must be called in the main thread. 

 Does it need to be running in your application? Usually you do most of the 
work on a secondary thread, then use dispatch_async() or so to send the parts 
that need to happen on the main thread back there. If you can't do that, 
another option would be to run the code on the main thread of another process, 
e.g. using XPC, and have that call you back when it needs to make your app do 
something on *its* main thread.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Modern API to read textClipping files

2016-09-23 Thread Uli Kusterer
On 23 Sep 2016, at 08:49, Allan Odgaard  wrote:
> Is there any non-deprecated API to read textClipping files?
> 
> FSOpenResFile() was deprecated in 10.8 but I haven’t found a way to replace 
> it. There is the com.apple.ResourceFork extended file attribute, but it seems 
> to be stored in some legacy format that I would rather not try to interpret.

AFAIK that's just the raw resource fork contents exposed in that extended 
attribute. I'm not aware of any API to read these files beyond the Resource 
Manager API.

If you change your opinion on reading it yourself, I wrote some code a while 
ago that reads resource forks:

https://github.com/uliwitness/ReClassicfication/blob/master/InterfaceLib/FakeResources.c

(There are more files in that folder, check out the entire project at 
https://github.com/uliwitness/ReClassicfication/)

Note that the code for writing out resource forks is still buggy, but the 
reading code works fine.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer
On 23 Sep 2016, at 01:19, Sandor Szatmari  wrote:
> // my .m file
> static NSString * const kMyContext = @"my fantastic context";

 This avoids the issue of having a different string in a different module and 
relying on details of your compiler and its optimizer. However, it can still 
run afoul of them, in the other direction, depending on which string you use: 
I've seen people do this and use the name of the property being observed as the 
string's value. Which is not an unlikely choice for an observation in the base 
class. And in that case, the optimizer might give the base class and you the 
same string to point to in your static variable.

 OTOH, if you use your subclass's name, you're less likely to collide. But why 
use the memory for the additional string and risk making the value less unique 
when

void *kMyContext = &kMyContext;

is *guaranteed* to give you a unique address that nobody else's object may 
occupy?

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer

> On 23 Sep 2016, at 01:07, Quincey Morris 
>  wrote:
> 
> On Sep 22, 2016, at 15:45 , Gabriel Zachmann  wrote:
>> 
>> Sure, but an observation method is what would be called a "callback" in 
>> plain C.
>> In C, I can have many different callbacks.
>> I don't see why that should not be possible in Obj-C - I just would need a 
>> mechanism to add tell the system the names / function pointers to be 
>> registered as observers.
> 
> It is of course possible in Obj-C. There are APIs that have a “didEnd” 
> selector, such as (deprecated) ‘[NSApplication 
> beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:]’. That’s 
> similar to the KVO notification method concept, except that you get to 
> specify a selector and a target object. Note, however, that such APIs tend to 
> have a context parameter, too**.
> 
> But that’s because the KVO notification mechanism is a more ancient design 
> concept, where it likely seemed simple, adequate and flexible. I assume it 
> comes from NeXTStep days (late 80s or early 90s), not OS X 10.0 days (early 
> 2000s), although I don’t know for sure.

 Are you sure? I only learned Cocoa when it came to OS X, but my impression was 
that, while KVC came from NeXT, KVO arrived with bindings … that would have 
been 10.3 or 10.4-ish?

> ** In the “didEnd” selector mechanism, the context parameter is likely used 
> for actual context information, rather than for identifying the source of the 
> invocation. It can be used that way with KVO notifications, too, but the fact 
> that they’re funneled through a single method in the observer object means 
> that the context is implicitly known anyway, and the context parameter has 
> been appropriated as a marker for the source of the observation.

 Yeah, I wouldn't conflate the context on beginSheet: and the majority of Cocoa 
calls with the one on KVO. And I would actually argue that you *should not* use 
the KVO context as actual storage, as as soon as it contains useful 
information, you can't tell it from someone else's context anymore (such as 
your superclass's). At the least using it for data would be bad style.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer
On 23 Sep 2016, at 00:45, Gabriel Zachmann  wrote:
>> Because the observer is an object. Your observation and a superclass 
>> observation come from the same object. Whether these are to be treated as 
>> different observations** cannot be determined automatically, hence the need 
>> for a “context”.
> 
> Sure, but an observation method is what would be called a "callback" in plain 
> C.
> In C, I can have many different callbacks.
> I don't see why that should not be possible in Obj-C - I just would need a 
> mechanism to add tell the system the names / function pointers to be 
> registered as observers.
> 
> Anyways, the concept of a block gets closer to what I mean, except it is 
> still not a named function/method.

 The problem is that KVO was designed (probably because it avoids the overhead 
of an NSInvocation, as the observeValueForKeyPath method can't be called using 
performSelector) to funnel all its callbacks through a single method on your 
object.

 If it allowed specifying a SEL to call, on the observer, you wouldn't need a 
context parameter.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer

> On 22 Sep 2016, at 19:53, Quincey Morris 
>  wrote:
> 
> On Sep 22, 2016, at 03:16 , Gabriel Zachmann  wrote:
>> 
>> That makes me wonder: why isn't it possible to register several, different 
>> observers for the same thing?
>> That way, I wouldn't need to care about observations I didn't create, would 
>> I?
> 
> Because the observer is an object. Your observation and a superclass 
> observation come from the same object. Whether these are to be treated as 
> different observations** cannot be determined automatically, hence the need 
> for a “context”.
> 
> The reason it’s messy is that the observer/notification API is old and 
> doesn’t follow modern API design practices. If this were being designed 
> today, the “observeValueForKeyPath…” method would likely be replaced by a 
> block/closure (similar to a completion handler) that’s passed as a parameter 
> to the “addObserver…” call, and there wouldn’t be any contexts.

Or it could be done like other places in Cocoa (was it NSTrackingArea? Or the 
event monitors?), where you get an "id" return value back (some unknown object) 
that represents your registration and that you keep around and pass to the 
remove call to specify which registration to unregister.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer
On 22 Sep 2016, at 04:00, 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.

 As your quote says:

> "Contexts chosen in a similar manner in the super- or subclass will be 
> unlikely to overlap."

 It is to insulate code inherited from a superclass that observes the same 
property as code in the superclass. By using a unique context as an additional 
identifier for the subscription, the subclass can't accidentally unsubscribe 
the base class that still wants to stay subscribed.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer

> On 22 Sep 2016, at 03:36, 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 idea either, because *other* observations — 
>> ones you don’t control — might use a value that’s not an object, or not even 
>> a valid pointer.
> 
> 
> Fair point.
> 
> 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.
> 
> So Gabriel’s alternative is basically to use a global address, as you 
> otherwise suggested.
> 
> void* tsk… *goes away muttering*

No. It is not supposed to be a refCon or userInfo. It's a unique identifier for 
this observation (which can't be "self", because then observations registered 
by a subclass would get the same identifier as observations registered by the 
base class, and if one unsubscribes or re-subscribes earlier than the other, 
one could remove the other's observation and would break things.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer

> On 22 Sep 2016, at 03:21, Slipp Douglas Thompson 
>  wrote:
> 
> 
>> 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 — 
>>> ones you don’t control — might use a value that’s not an object, or not 
>>> even a valid pointer.
>> 
> 
> I see your point about context plausibly not being neither an NSObject nor 
> nil.  While you could check if context is an NSObject beforehand (is there 
> even a reliable way to do this?  CocoaWithLove 
> 
>  couldn't find a great approach ;-/)— I think coding consistently against all 
> other addObserver: calls in your app is a good-enough solution.  I.E. If you 
> implement observeValueForKeyPath: with [context isEqual: …] checks, make sure 
> all the other addObserver: calls (for those same keys, at least) are using 
> nil or NSObjects.

That's not enough. You would also have to ensure that none of Apple's code uses 
a non-object context in any KVOs it installs on any of your objects.

Which you can't.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer

> On 22 Sep 2016, at 02:05, 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.
> 
> Let me try to paraphrase, in order to check whether I am understanding 
> correctly.
> 
> 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 occurrences of the two literals, 
> thus effectively storing only one literal?

 This is an optimization that Apple's compiler (and most compilers) currently 
apply for string constants, yes. However, they can only do that in the same 
executable. I.e. a framework or loadable plug-in bundle will get its own copy, 
as we can't know whether the executable loading it already has its own copy of 
that string or not. Also, of course, if you have an NSMutableString that ends 
up having the same content as an NSString, you get different addresses.

 If you want a more detailed answer, I blogged about this a while ago:

http://orangejuiceliberationfront.com/cocoa-string-comparisons-and-the-optimizer/

>> So, this technique is generally Not A Good Idea™.
> 
> If my understanding is correct, then I wholeheartedly agree.
> 
> That brings me to another question.  I've got this piece of code from an 
> example on MLMediaLibrary.
> 
> This is how I start the whole thing:
> 
>  [mediaLibrary_ addObserver: self
>  forKeyPath: @"mediaSources"
> options: 0
> context: (__bridge void *) @"mediaLibraryLoaded"];
> 
> And this is the beginning of the corresponding KVO:
> 
> - (void) observeValueForKeyPath: (NSString *) keyPath   ofObject: (id) object
>   change: (NSDictionary *) change context: (void *) 
> context
> {
>  MLMediaSource * mediaSource = [mediaLibrary_.mediaSources objectForKey: 
> MLMediaSourcePhotosIdentifier];
>  if ( context == (__bridge void *) @"mediaLibraryLoaded" )
>  {
> 
> So what would be the proper way to do it?  Should I just define my own string 
> constant?

Do

void *kMediaLibraryLoadedKVOContext = &kMediaLibraryLoadedKVOContext;

for more details, see my other message in this thread.

-- Uli


___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer
On 22 Sep 2016, at 02:02, Doug Hill  wrote:
>>> My question is: how can the compiler know that '==' in this case is a 
>>> NSString comparison?
>>> Or is some other magic going on here? if so, which?
>>> Does the compiler know it should perform some kind of dynamic method 
>>> dispatch?
>> 
>> My guess, without seeing the code that set up the observer, is that it was 
>> also set up with @"mediaLibraryLoaded", and the compiler collects and reuses 
>> string constants, so the address is the same. I'd guess that if you ensure 
>> that the string is a unique variable, it won't work.
>> 
>> NSString* s = [NSString stringWithFormat:@"%@%@%@", @"media", @"Library", 
>> @"Loaded"];
>> if(context == (__bridge void*)s)
>> 
>> Steve via iPad
> 
> For the above test, you could also try turning off the LLVM code-gen setting 
> "gcc_reuse_strings".
> (Which parenthetically, you probably wouldn't want to do in shipping code, 
> particularly if you have a lot of strings.)
> 
> But yeah, as everyone says, it's generally not a good thing to rely upon this 
> behavior, and just use -[NSString isEqual:]

 Do *not* call methods on the context to a KVO observation! It is not 
guaranteed to actually be an object! It is not storage for user data, it is 
simply a unique identifier for your subscription to these KVO callbacks.

-- Uli
___

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: Stupid objective-c question

2016-09-23 Thread Uli Kusterer

> On 22 Sep 2016, at 02:01, Graham Cox  wrote:
> 
> 
>> 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" )

Gabriel,

this is a pointer comparison, not a string comparison. If the addObserver call 
happens in another module (usually unlikely) or Apple changes how its compiler 
coalesces string constants, this will break.

> Don’t do this, even if it appears to work. You got lucky, or are taking 
> advantage of undocumented implementation details.
> 
> This should be: if([(NSString*)context 
> isEqualToString:@“mediaLibraryLoaded”])…
> 
> I expect the first thing -isEqualToString: does is a pointer comparison, so 
> it’s unlikely to be significantly less performant for the case of when the 
> pointers are literally identical.

No, Graham, don't do that!

There is no guarantee that the context is a valid object. It is just supposed 
to be a unique pointer value so your class can tell a KVO notification from 
notifications for other observers on the same object (e.g. if a subclass 
observes the same value as a base class).

The best (but a bit clever) way to declare your context is

void* kMediaLibraryLoadedContext = &kMediaLibraryLoadedContext;

this may look invalid, but actually just reserves a bit of memory in your app's 
globals section that now has a unique address. As a convenience, it writes this 
address into itself. So instead of &kMediaLibraryLoadedContext you can just 
write kMediaLibraryLoadedContext.

Cheers,
-- Uli



___

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: CALayer kCAGravityResizeAspectFill and kCAGravityTop

2016-09-23 Thread Torsten Curdt
>
>
> Its still an option, especially if you are otherwise using UIViews –
> UIView.maskView would do the trick.
>

Wow - I wasn't even aware that exists. Nice!

Thanks!
___

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: IKImageBrowserView keeps scrolling to the bottom

2016-09-23 Thread Steve Mills
On Sep 23, 2016, at 15:05:38, James Crate  wrote:
> 
> I thought the same thing. I haven’t installed Sierra yet, so maybe it works 
> if you build with Xcode 8 on Sierra. For now, if you go back to Xcode 7 it 
> will should work like before, but I haven’t tried that yet either. I needed 
> Xcode 8 to test/fix an iOS app on iOS 10, and I’m not sure how painful 
> switching back and forth between Xcode 7 and Xcode 8 will be, or even if 
> Xcode 7 can be downloaded.

I've had multiple Xcodes installed before, and there's no problem switching 
back and forth.

> Another wrinkle is that Xcode 8 updated subversion from 1.7.x to 1.9.x, which 
> required subversion repositories to be upgraded. So, if svn 1.7.x can’t read 
> repositories upgraded for 1.9.x, there could be other problems to work around.

I use git.

> So given all that, it’s probably easier to switch to NSCollectionView than 
> figure out how to switch back and forth between Xcode 7 and 8. However, the 
> new NSCollectionView features require 10.9, so if you have requirements to 
> support older systems…your guess is as good as mine.

Easier? Not by a long damn shot. It took me most of the day to get 
NSCollectionView and its many support classes figured out and working. Plus it 
doesn't do all the nifty caching and scaling that IKImageBrowserView does.

> In iOS 7 (I think, or maybe 8) there was an NSTableView bug I ran into in the 
> initial release. I was able to work around it, but it was fixed in a x.0.1 
> release. So right now I’m just hoping there will be an Xcode 8.0.1 release 
> that will fix this problem.

This is Mac only, so I don't care about iOS. Yes, it'd be really nice if Apple 
would release a fix for this obvious bug. Not sure how a compiler and SDK could 
even cause such a thing at runtime.

--
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/archive%40mail-archive.com

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

Re: IKImageBrowserView keeps scrolling to the bottom

2016-09-23 Thread James Crate
On Sep 23, 2016, at 1:35 PM, Steve Mills  wrote:
> 
> On Sep 23, 2016, at 12:21:56, James Crate  wrote:
>> 
>> I saw the same thing when I updated to Xcode 8 last week. A sample app with 
>> no subclassing displays the same behavior. I filed a radar with sample 
>> project as well. 
>> 
>> The documentation for IKImageBrowserView now says it is effectively 
>> deprecated so I guess we may be forced to upgrade to NSCollectionView.  
> 
> W. T. F. That's just great. "will be deprecated in a future release." If it's 
> not yet deprecated and I'm still at 10.11.3, why is it so obviously broken?

I thought the same thing. I haven’t installed Sierra yet, so maybe it works if 
you build with Xcode 8 on Sierra. For now, if you go back to Xcode 7 it will 
should work like before, but I haven’t tried that yet either. I needed Xcode 8 
to test/fix an iOS app on iOS 10, and I’m not sure how painful switching back 
and forth between Xcode 7 and Xcode 8 will be, or even if Xcode 7 can be 
downloaded. 

Another wrinkle is that Xcode 8 updated subversion from 1.7.x to 1.9.x, which 
required subversion repositories to be upgraded. So, if svn 1.7.x can’t read 
repositories upgraded for 1.9.x, there could be other problems to work around.

So given all that, it’s probably easier to switch to NSCollectionView than 
figure out how to switch back and forth between Xcode 7 and 8. However, the new 
NSCollectionView features require 10.9, so if you have requirements to support 
older systems…your guess is as good as mine.

In iOS 7 (I think, or maybe 8) there was an NSTableView bug I ran into in the 
initial release. I was able to work around it, but it was fixed in a x.0.1 
release. So right now I’m just hoping there will be an Xcode 8.0.1 release that 
will fix this problem.

Jim Crate


___

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: IKImageBrowserView keeps scrolling to the bottom

2016-09-23 Thread Steve Mills
On Sep 23, 2016, at 12:21:56, James Crate  wrote:
> 
> I saw the same thing when I updated to Xcode 8 last week. A sample app with 
> no subclassing displays the same behavior. I filed a radar with sample 
> project as well. 
> 
> The documentation for IKImageBrowserView now says it is effectively 
> deprecated so I guess we may be forced to upgrade to NSCollectionView.  

W. T. F. That's just great. "will be deprecated in a future release." If it's 
not yet deprecated and I'm still at 10.11.3, why is it so obviously broken?

--
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/archive%40mail-archive.com

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

Re: IKImageBrowserView keeps scrolling to the bottom

2016-09-23 Thread James Crate
On Sep 23, 2016, at 1:01 PM, Steve Mills  wrote:
> 
> I just noticed that the most recent build of my app was scrolling the image 
> browser view constantly to the bottom. I can scroll up once it gets to the 
> bottom, but it then scrolls back down. I can change the sort order, but it 
> keeps scrolling to the bottom no matter what. I have it subclassed, but only 
> to handle methods for printing.
> 
> I recently updated to Xcode 8, still at OS X 10.11.6.
> 
> Any ideas? Any methods I could try overriding to see what's going on? I tried 
> setting a notification observer for NSScrollViewDidLiveScrollNotification, 
> but that's only being sent when I manually scroll.

I saw the same thing when I updated to Xcode 8 last week. A sample app with no 
subclassing displays the same behavior. I filed a radar with sample project as 
well. 

The documentation for IKImageBrowserView now says it is effectively deprecated 
so I guess we may be forced to upgrade to NSCollectionView.  

Jim Crate


___

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

IKImageBrowserView keeps scrolling to the bottom

2016-09-23 Thread Steve Mills
I just noticed that the most recent build of my app was scrolling the image 
browser view constantly to the bottom. I can scroll up once it gets to the 
bottom, but it then scrolls back down. I can change the sort order, but it 
keeps scrolling to the bottom no matter what. I have it subclassed, but only to 
handle methods for printing.

I recently updated to Xcode 8, still at OS X 10.11.6.

Any ideas? Any methods I could try overriding to see what's going on? I tried 
setting a notification observer for NSScrollViewDidLiveScrollNotification, but 
that's only being sent when I manually scroll.

--
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/archive%40mail-archive.com

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

Re: iOS Application influencing a running web app?

2016-09-23 Thread Pascal Bourguignon
A web application has a bunch of urls, each connected to a different function. 
Define an url to set a parameter and connect it to the function that sets this 
parameter. Use this url only in the iOS application. You may want to use some 
authentication protocol to authorize the parameter setting, but this should be 
already provided by your web application framework. 

-- 
__Pascal Bourguignon__

> Le 23 sept. 2016 à 16:46, Eric E. Dolecki  a écrit :
> 
> Thanks for your reply. I'm not sure I'm following, though. Do you mean to 
> send it query strings? I could make the HTML page of the app a PHP page. If 
> that's what you meant.
> 
> Eric
> 
>> On Fri, Sep 23, 2016 at 10:42 AM Pascal Bourguignon  
>> wrote:
>> Just write some http app on the laptop, and hit it with requests (urls) from 
>> the iOS app; this would be the Q&D way to do it easily and with some level 
>> of security (https).
>> 
>> Since you already have a web app, you can just add some admin requests to it.
>> --
>> __Pascal Bourguignon__
>> 
>> > Le 23 sept. 2016 à 16:27, Eric E. Dolecki  a écrit :
>> >
>> > I am going to have a web application running on a local laptop - which runs
>> > various a prototype of a user experience.
>> >
>> > I've been asked to add an iOS application to the mix, to control parameters
>> > in the running app on the laptop.
>> >
>> > What might be the best way to architect this type of set up (and also
>> > easiest)? Have the web app poll a file for contents - and have the iOS app
>> > talk to a PHP page with POSTs of values and write to that file - and have
>> > my app poll it? Sounds terrible. Some AJAX thing? I'd like to avoid a
>> > database if possible.
>> >
>> > Just throwing this out there. If it's too off-topic, please disregard this.
>> >
>> > Thanks,
>> > Eric
>> > ___
>> >
>> > 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/pjb%40informatimago.com
>> >
>> > This email sent to p...@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/archive%40mail-archive.com

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

Re: iOS Application influencing a running web app?

2016-09-23 Thread Eric E. Dolecki
Thanks for your reply. I'm not sure I'm following, though. Do you mean to
send it query strings? I could make the HTML page of the app a PHP page. If
that's what you meant.

Eric

On Fri, Sep 23, 2016 at 10:42 AM Pascal Bourguignon 
wrote:

> Just write some http app on the laptop, and hit it with requests (urls)
> from the iOS app; this would be the Q&D way to do it easily and with some
> level of security (https).
>
> Since you already have a web app, you can just add some admin requests to
> it.
> --
> __Pascal Bourguignon__
>
> > Le 23 sept. 2016 à 16:27, Eric E. Dolecki  a écrit :
> >
> > I am going to have a web application running on a local laptop - which
> runs
> > various a prototype of a user experience.
> >
> > I've been asked to add an iOS application to the mix, to control
> parameters
> > in the running app on the laptop.
> >
> > What might be the best way to architect this type of set up (and also
> > easiest)? Have the web app poll a file for contents - and have the iOS
> app
> > talk to a PHP page with POSTs of values and write to that file - and have
> > my app poll it? Sounds terrible. Some AJAX thing? I'd like to avoid a
> > database if possible.
> >
> > Just throwing this out there. If it's too off-topic, please disregard
> this.
> >
> > Thanks,
> > Eric
> > ___
> >
> > 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/pjb%40informatimago.com
> >
> > This email sent to p...@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/archive%40mail-archive.com

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

Re: iOS Application influencing a running web app?

2016-09-23 Thread Pascal Bourguignon
Just write some http app on the laptop, and hit it with requests (urls) from 
the iOS app; this would be the Q&D way to do it easily and with some level of 
security (https). 

Since you already have a web app, you can just add some admin requests to it. 
-- 
__Pascal Bourguignon__

> Le 23 sept. 2016 à 16:27, Eric E. Dolecki  a écrit :
> 
> I am going to have a web application running on a local laptop - which runs
> various a prototype of a user experience.
> 
> I've been asked to add an iOS application to the mix, to control parameters
> in the running app on the laptop.
> 
> What might be the best way to architect this type of set up (and also
> easiest)? Have the web app poll a file for contents - and have the iOS app
> talk to a PHP page with POSTs of values and write to that file - and have
> my app poll it? Sounds terrible. Some AJAX thing? I'd like to avoid a
> database if possible.
> 
> Just throwing this out there. If it's too off-topic, please disregard this.
> 
> Thanks,
> Eric
> ___
> 
> 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/pjb%40informatimago.com
> 
> This email sent to p...@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/archive%40mail-archive.com

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

iOS Application influencing a running web app?

2016-09-23 Thread Eric E. Dolecki
I am going to have a web application running on a local laptop - which runs
various a prototype of a user experience.

I've been asked to add an iOS application to the mix, to control parameters
in the running app on the laptop.

What might be the best way to architect this type of set up (and also
easiest)? Have the web app poll a file for contents - and have the iOS app
talk to a PHP page with POSTs of values and write to that file - and have
my app poll it? Sounds terrible. Some AJAX thing? I'd like to avoid a
database if possible.

Just throwing this out there. If it's too off-topic, please disregard this.

Thanks,
Eric
___

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: Stupid objective-c question

2016-09-23 Thread Sandor Szatmari
Thanks to both of you for clarifying this and for a nice solution.

Basically then, I must not use address pointed to, but instead, the address of 
the pointer itself.

I liked the readability of using a string, but I think there is too much room 
for misinterpretation, conflating the contents of the string with the 
uniqueness requirement.

Regards,
Sandor Szatmari

> On Sep 23, 2016, at 05:04, Quincey Morris 
>  wrote:
> 
>> On Sep 23, 2016, at 01:36 , Alastair Houghton  
>> wrote:
>> 
>> Note that you can use *any* type for your variable; in some ways, it might 
>> make sense to use a non-pointer type, just to make clear that it’s the 
>> address that matters, e.g.
>> 
>> static const int kMyContext = 0xabadf00d;
>> 
>> Otherwise some smart-ass might go and delete the “&” operators from your 
>> code, and that makes it vulnerable to problems.
> 
> As previously mentioned, the safest way to do this is:
> 
>> static void* kMyContext = &kMyContext;
> 
> 
> That makes the “&” optional (at comparison time), and it should even avoid 
> the coalescing problem if it’s declared const.
> 
> ___
> 
> 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/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@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

Re: Stupid objective-c question

2016-09-23 Thread Alastair Houghton
On 23 Sep 2016, at 10:04, Quincey Morris  
wrote:
> 
>> static void* kMyContext = &kMyContext;
> 
> That makes the “&” optional (at comparison time), and it should even avoid 
> the coalescing problem if it’s declared const.

Yes, that’s a good way to do it.

It might be a good idea for Apple to have a macro for this purpose, so you 
could write

  NS_DECLARE_KVO_CONTEXT(kMyContext);

as that would avoid any confusion whatsoever (filed as rdar://2842).

Kind regards,

Alastair.

--
http://alastairs-place.net


___

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: Stupid objective-c question

2016-09-23 Thread Jonathan Mitchell

> On 23 Sep 2016, at 10:04, Quincey Morris 
>  wrote.
> 
> As previously mentioned, the safest way to do this is:
> 
>> static void* kMyContext = &kMyContext;
> 
Thats a neat trick. It’s not an initialisation that I have seen before and on 
first glance I thought it was a typo but it works.
I normally go with:

static char myContext;

However, being able to ditch the address of operator has some appeal.


___

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: Stupid objective-c question

2016-09-23 Thread Quincey Morris
On Sep 23, 2016, at 01:36 , Alastair Houghton  
wrote:
> 
> Note that you can use *any* type for your variable; in some ways, it might 
> make sense to use a non-pointer type, just to make clear that it’s the 
> address that matters, e.g.
> 
>  static const int kMyContext = 0xabadf00d;
> 
> Otherwise some smart-ass might go and delete the “&” operators from your 
> code, and that makes it vulnerable to problems.

As previously mentioned, the safest way to do this is:

> static void* kMyContext = &kMyContext;


That makes the “&” optional (at comparison time), and it should even avoid the 
coalescing problem if it’s declared const.

___

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: Stupid objective-c question

2016-09-23 Thread Alastair Houghton
On 23 Sep 2016, at 09:36, Alastair Houghton  
wrote:
> 
> Note that you can use *any* type for your variable; in some ways, it might 
> make sense to use a non-pointer type, just to make clear that it’s the 
> address that matters, e.g.
> 
>  static const int kMyContext = 0xabadf00d;

On second thoughts, it might also be best not to use “const”, as that might 
conceivably also get coalesced.  So

   static int kMyContext;

would do.  No need to initialise - you don’t care about the value.

Kind regards,

Alastair.

--
http://alastairs-place.net


___

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: Stupid objective-c question

2016-09-23 Thread Alastair Houghton
On 23 Sep 2016, at 00:07, Quincey Morris  
wrote:
> 
> On Sep 22, 2016, at 15:45 , Gabriel Zachmann  wrote:
>> 
>> Sure, but an observation method is what would be called a "callback" in 
>> plain C.
>> In C, I can have many different callbacks.
>> I don't see why that should not be possible in Obj-C - I just would need a 
>> mechanism to add tell the system the names / function pointers to be 
>> registered as observers.
> 
> It is of course possible in Obj-C. There are APIs that have a “didEnd” 
> selector, such as (deprecated) ‘[NSApplication 
> beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:]’. That’s 
> similar to the KVO notification method concept, except that you get to 
> specify a selector and a target object. Note, however, that such APIs tend to 
> have a context parameter, too**.
> 
> But that’s because the KVO notification mechanism is a more ancient design 
> concept, where it likely seemed simple, adequate and flexible. I assume it 
> comes from NeXTStep days (late 80s or early 90s), not OS X 10.0 days (early 
> 2000s), although I don’t know for sure.

KVO is an OS X thing, introduced in 10.3.

Why it uses this approach rather than taking a selector is a good question.  I 
imagine it’s motivated by the desire to allow subclasses to override 
superclasses’ observation behaviour, and perhaps there might also be a 
performance argument (it *might* make it more likely that the 
-observeValueForKeyPath: method hits the method cache, and/or provide 
additional opportunities to use IMPs).

Kind regards,

Alastair.

--
http://alastairs-place.net


___

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: Stupid objective-c question

2016-09-23 Thread Alastair Houghton
On 23 Sep 2016, at 00:19, Sandor Szatmari  wrote:
> 
> I wanted to get some opinions on the following which I have done in the past 
> and perceive as different because the string constant is introduced and 
> defined once and only once.
> 
> // my .m file
> static NSString * const kMyContext = @"my fantastic context";
> 
> // later on
> - (void) observeValueForKeyPath: (NSString *) keyPath   ofObject: (id) object
>   change: (NSDictionary *) change context: (void *) 
> context
> {
>  if ( context == kMyContext )
>  { // do my stuff }
>  else
>  // call super
> }
> 
> My interpretation of how to use context has been as an arbitrary pointer...  
> Does this run afoul of anyone's sensibility?

Yes, it’s wrong.

The compiler and linker perform an optimisation known as string coalescing.  
What this means is that if *anyone* else uses the string @"my fantastic 
context" in their code and it just happens to get (statically) linked to yours, 
the address will not be unique.  Given the string you picked, it isn’t unlikely 
that the same string could be used elsewhere as a KVO context.

At present, the risk is confined mainly to your own codebase because string 
coalescing isn’t performed by the dynamic linker and the system doesn’t intern 
string constants.

The correct approach is to take *the address of a static variable* and use 
that, as that’s guaranteed to be unique.

i.e. you need to do this:

  static NSString * const kMyContext = @"My fantastic context";

  ...

[foo addObserver:myObject forKeyPath:@"some.key.path" options:0 
context:&kMyContext];

  ...

  - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
  change:(NSDictionary *)change context:(void *)context
  {
if (context == &kMyContext) {
  // Do my stuff
} else {
  [super observeValueForKeyPath:keyPath ofObject:object change:change 
context:context];
}
  }

Note that you can use *any* type for your variable; in some ways, it might make 
sense to use a non-pointer type, just to make clear that it’s the address that 
matters, e.g.

  static const int kMyContext = 0xabadf00d;

Otherwise some smart-ass might go and delete the “&” operators from your code, 
and that makes it vulnerable to problems.

Kind regards,

Alastair.

--
http://alastairs-place.net


___

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