__bridge_transfer on a method return value
I'm using CFURLCreateStringByAddingPercentEscapes() because the NSString version leaves '+' signs unescaped. If I used it directly in code I'd either CFRelease it, or if assigned to an NSString, __bridge_transfer it. However I want it as the return value of a method. So I wrote this +(NSString*)webEncodedString:(NSString *)string { CFStringRef retval = CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)string, NULL, CFSTR( !*'();:@=+$,/?%#[] ), kCFStringEncodingUTF8 ); return( __bridge_transfer NSString*)retval; } My confusion comes from not knowing whether this function now returns an object with a +1 refcount or not. If it does it needs to be renamed to have new or copy etc in the method name, or annotated properly to show that. My first thought was that yes the transfer means the return value has a +1 refcount. Then I wondered if the __bridge_transfer transfers ownership to some temporary inside the method which will be released as it goes out of scope and do the job so all retains/releases are balanced out and the return value does not have an extra retain on it. I suppose if I wrote the same thing like this it highlights the difference +(NSString*)webEncodedString:(NSString *)string { CFStringRef retval = CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)string, NULL, CFSTR( !*'();:@=+$,/?%#[] ), kCFStringEncodingUTF8 ); NSString *temp = (__bridge_transfer)retval; return temp; } Here it would seem the ownership passes to temp, which goes out of scope at the end of the method and would release, after I assume some retains/autoreleases are done to ensure the object lives long enough to make it back to the caller, but still balanced. Which is it? ___ 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: __bridge_transfer on a method return value
On May 9, 2012, at 23:07 , Roland King wrote: I'm using CFURLCreateStringByAddingPercentEscapes() because the NSString version leaves '+' signs unescaped. If I used it directly in code I'd either CFRelease it, or if assigned to an NSString, __bridge_transfer it. However I want it as the return value of a method. So I wrote this +(NSString*)webEncodedString:(NSString *)string { CFStringRef retval = CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)string, NULL, CFSTR( !*'();:@=+$,/?%#[] ), kCFStringEncodingUTF8 ); return( __bridge_transfer NSString*)retval; } My confusion comes from not knowing whether this function now returns an object with a +1 refcount or not. If it does it needs to be renamed to have new or copy etc in the method name, or annotated properly to show that. My first thought was that yes the transfer means the return value has a +1 refcount. Then I wondered if the __bridge_transfer transfers ownership to some temporary inside the method which will be released as it goes out of scope and do the job so all retains/releases are balanced out and the return value does not have an extra retain on it. I suppose if I wrote the same thing like this it highlights the difference +(NSString*)webEncodedString:(NSString *)string { CFStringRef retval = CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)string, NULL, CFSTR( !*'();:@=+$,/?%#[] ), kCFStringEncodingUTF8 ); NSString *temp = (__bridge_transfer)retval; return temp; } Here it would seem the ownership passes to temp, which goes out of scope at the end of the method and would release, after I assume some retains/autoreleases are done to ensure the object lives long enough to make it back to the caller, but still balanced. You're correct that the two versions are equivalent at the point of return. I believe the balance sheet looks like this in the first case: +1 assumed by the bridge transfer to have already happened -1 from completing the expression containing the bridge transfer +1 to the return expression result -1 from returning Thus the net retain count is 0, but the return statement ensures that the object survives at least until the caller has a chance to retain it. This might be via an autorelease, or may be something more optimal. The balance sheet for the second case looks like this: +1 assumed by the bridge transfer to have already happened -1 from completing the expression containing the bridge transfer +1 from the assignment to temp +1 to the return expression result -1 from temp going out of scope -1 from returning So the net is still 0. This is all on the basis of: http://clang.llvm.org/docs/AutomaticReferenceCounting.html in sections 3.2.3, 3.2.4 and 4.2. The only differences that calling this method 'newWebEncodedString' would make (AFAIK) are that the return value would never need to be autoreleased, the final release from the return statement wouldn't happen, and the caller would have slightly different code because of the guaranteed +1 retain count. ___ 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: saveDocument:
On Thu, May 10, 2012 at 2:24 AM, Graham Cox graham@bigpond.com wrote: If you build a document-based app using Xcode's template, it will work correctly from the very first time you run it. Then you can see how it's put together, and all of these things will slowly become obvious. I'm doing precisely this. I run two projects in parallel, one by Xcode, one by hand and compare the findings. The problem I have right now is that the one from Xcode just works and I don't know why, it seems to do lots of things under the hood. For instance, MyDocument.m does not even have to have dataOfType:error: or readFromData:ofType:error: in order to show Save as enabled in the menu. On the other hand, yes, that's something I totally did not anticipate so I guess I learned something new. At the very least if you insist on this approach, you should read all of the documentation thoroughly, so you understand the (many) concepts that lie behind Cocoa's architecture. I'm reading, really. ___ 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: Accessibility issues with NSPopover
Thanks, but the accessibility-dev is by itself arcane, to say nothing of Accessibility engineers.. :) I've been trying to get useful info there for many issues I had in the past, to no avail. I was hoping to have at least the non-accessibility issues helped here. does anybody know how to regain focus on an NSPopover after it lost user focus? (after another window becomes key and main) I could not do it. The only way I found was to close/delete the NSPopover and recreate it. Seems bad solution to me. On 9 במאי 2012, at 18:38, Fritz Anderson wrote: On 9 May 2012, at 7:16 AM, Motti Shneor wrote: I am experiencing grave problems setting up decent accessibility on my NSPopover. Most issues affect VoiceOver users, but some affect all users (not even accessibility). Accessibility can be arcane (and buggy). Your best bet is the accessibility-dev list. An accessibility engineer follows it fairly closely. — F Motti Shneor, Mac OS X Software Architect Team Leader Spectrum Reflections Ltd. ___ 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: saveDocument:
On Wed, May 9, 2012 at 5:40 PM, Quincey Morris quinceymor...@rivergatesoftware.com wrote: Very occasionally, it's necessary to subclass the NSDocumentController and force the singleton to your own subclass, but this is rare. This is what I try to do - subclass the NSDocumentController in applicationWillFinishLaunching:. Thus, for example, the 'saveDocument:' action will be normally be delivered to the NSDocument-subclass object directly, because it is in the responder chain that's active when the menu item is chosen. Note that NSDocument *has* a 'saveDocument:' method; NSDocumentController doesn't. Ok. My NSDocument has saveDocument:, and my NSDocumentController doesn't have it. But the menu has Save as disabled. Thanks for the links, there is also: http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MenuList/Articles/EnablingMenuItems.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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: monitoring changes in a local property
I'm going to re-read Chapter 31 and 32 of Hillegass' book, which more or less cover this subject (view swapping and core data relations). Briefly what he does is is adding a MOC property to each view controller, so its views can use that. I'll post back later. - Koen. On May 10, 2012, at 12:39 AM, Quincey Morris wrote: On May 9, 2012, at 19:56 , Koen van der Drift wrote: In my case, the contentset of the array controller is bound to a tree controller (which is bound to the MOC of my model). I fail to see how I also bind it to an array. Well, as to a direct answer, I'm stumped. If the array controller is in entity mode, AFAICT there's no binding (to the data model) that would let the data model keep track of what's selected via bindings. There simply appears to be no equivalent to the selectionIndexes binding when in entity mode.** So you have 2 choices that I can see: 1. Shrug and have your view controller monitor the array controller's selectedObjects directly. 2. Have your *app delegate* monitor the array controller's selectedObjects, and provide the result as a public KVO-compliant property. This would keep the implementation of how the selection is determined as a private detail of the app delegate, preventing the array controller dependency from spreading throughout your application design. ** It's possible that NSArrayController maintains selectionIndexes when the content is a NSOrderedSet, in Lion. In that case, you can maintain (via bindings) both a tree selectionIndexPaths and an ordered set selectionIndexes property in the app delegate, then retrieve the selected myThings objects via a two-step lookup process. I wouldn't bet on it working, though. ___ 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: saveDocument:
It works now! The problem was, that I was creating the window manager with init:, instead of the initializers from the docs. Thank you all for the replies, they were very helpful! ___ 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: saveDocument:
On 10/05/2012, at 7:12 PM, ecir hana wrote: This is what I try to do - subclass the NSDocumentController in applicationWillFinishLaunching:. Subclassing NSDocumentController is extremely rare, and in almost every case, unnecessary. If you're doing this as a matter of course because you think you need to, you're almost certainly mistaken. I have subclassed this once, and that was because I needed to exclude certain files specifically from the Recent Items menu, and that was the sole reason. Forget about this class, it really just sits there and does its thing and you don't need to worry about it. Its main job is to create the relevant document instance when a file is opened from disk - after that the document itself is fairly autonomous. One of the main inputs to NSDocumentController is the app's property list (info.plist). Ok. My NSDocument has saveDocument:, and my NSDocumentController doesn't have it. But the menu has Save as disabled. There is a lot of interaction between the document and the application's info.plist, which describes the file types that the app can read and write and how those files types map to document (sub)classes. There is also the dirty state of the document to consider which in turn is influenced strongly by the state of any associated undo manager. Again, stumbling across the correct precise set of connections by trying to build this bottom-up is unlikely to work. For instance, MyDocument.m does not even have to have dataOfType:error: or readFromData:ofType:error: in order to show Save as enabled in the menu Indeed, that is quite true, and perfectly logical. Because the state of the menu has nothing to do with the actual data read or written by the document to disk, but by its internal state. After all, the user needs to choose a destination for a Save As before data can be written to that file, so the menu must be enabled and handled long before the document is asked to supply the file data to be written. Also, reading data from a file has very little influence on the Save As menu, except that it will clear the dirty state initially. How the document interprets a file's content is up to it, and it is not required to maintain that file data internally or keep the file open, for example. It is very common for a document to read a file into some totally different internal form, manage that while the document is open, then write it out to a file when required. --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
[MEET] CocoaHeadsNYC tonight (Thursday), 6:30PM
Paul Kim will give a talk entitled Let's Build A Text Editor. In this talk, I'll touch on a couple different aspects of Cocoa's text system in the context of a simple code editor. In particular, I'll show how to display line numbers and do basic syntax coloring. Followed as usual by pizza at Patsy's. See here for location and contact info: http://www.cocoaheadsnyc.org/meeting/ Note that this month Ed can't make it, so if necessary, call me. --Andy ___ 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
[ANN] Online ScriptingBridge documentation archive
The ScriptingBridge is a great way to automate applications either from Obj-C or from a Cocoa language (either a bridge or a native implementation such as F-script or Nu). We are establishing an online archive of browsable ScriptingBridge and AppleScript derived documentation to assist with Cocoa application automation scripting at: http://www.mugginsoft.com/kosmictask/ScriptingBridge The ScriptingBridge documentation is generated directly from an application's bundle using the sdef and sdp tools and then rendered using Doxygen If you would like to contribute to the archive (either as a user of a particular application or as the developer of a scriptable application) then see: http://www.mugginsoft.com/kosmictask/ScriptingBridge/submit-documentation Submissions can be made either via email or github Regards Jonathan Mitchell Mugginsoft LLP ___ 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: __bridge_transfer on a method return value
On May 10, 2012, at 1:07 AM, Roland King wrote: My confusion comes from not knowing whether this function now returns an object with a +1 refcount or not. If it does it needs to be renamed to have new or copy etc in the method name, or annotated properly to show that. I think you have this backward. You are giving ownership over to ARC. ARC decides what to do in part based on the method name. You don't pick the method name to match the behavior you anticipate from ARC, ARC picks its behavior based on the name, which should reflect your chosen semantics. Since your method name doesn't indicate that it returns ownership, ARC will autorelease the value. [If the caller is also compiled with ARC, then it hardly matters. It will decide how to behave also based on the method name and the two behaviors will complement each other (and, depending on optimizations, cancel out so that neither an autorelease nor a retain happens). If the caller is MRC, then ARC autoreleasing the return value is, of course, important given your method name.] Regards, Ken ___ 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: __bridge_transfer on a method return value
On May 10, 2012, at 11:54 PM, Ken Thomases wrote: On May 10, 2012, at 1:07 AM, Roland King wrote: My confusion comes from not knowing whether this function now returns an object with a +1 refcount or not. If it does it needs to be renamed to have new or copy etc in the method name, or annotated properly to show that. I think you have this backward. You are giving ownership over to ARC. ARC decides what to do in part based on the method name. You don't pick the method name to match the behavior you anticipate from ARC, ARC picks its behavior based on the name, which should reflect your chosen semantics. Since your method name doesn't indicate that it returns ownership, ARC will autorelease the value. [If the caller is also compiled with ARC, then it hardly matters. It will decide how to behave also based on the method name and the two behaviors will complement each other (and, depending on optimizations, cancel out so that neither an autorelease nor a retain happens). If the caller is MRC, then ARC autoreleasing the return value is, of course, important given your method name.] Regards, Ken Nicely put Ken and thanks too to Quincey who said much the same thing. I'd gotten stuck thinking that I had to figure out ownership and be explicit about it to match the method instead of understanding I just need to tell ARC what semantics I want when an object moves from CoreFoundation to Cocoa and let it sort it out what to do later based on the name and attributes of the method, which of course other code, ARC and non-ARC will then interpret correctly. ARC continues to be a very well thought out framework which hasn't let me down yet. Now back to the keychain API on iOS .. possibly not quite as coherent. Thanks both, I'm much happier now. ___ 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: __bridge_transfer on a method return value
On May 10, 2012, at 8:54 AM, Ken Thomases k...@codeweavers.com wrote: On May 10, 2012, at 1:07 AM, Roland King wrote: My confusion comes from not knowing whether this function now returns an object with a +1 refcount or not. If it does it needs to be renamed to have new or copy etc in the method name, or annotated properly to show that. I think you have this backward. You are giving ownership over to ARC. ARC decides what to do in part based on the method name. You don't pick the method name to match the behavior you anticipate from ARC, ARC picks its behavior based on the name, which should reflect your chosen semantics. Since your method name doesn't indicate that it returns ownership, ARC will autorelease the value. [If the caller is also compiled with ARC, then it hardly matters. It will decide how to behave also based on the method name and the two behaviors will complement each other (and, depending on optimizations, cancel out so that neither an autorelease nor a retain happens). If the caller is MRC, then ARC autoreleasing the return value is, of course, important given your method name.] This logic is clearer if you use the CFBridgingRetain() and CFBridgingRelease() functions instead of the __bridge_retained and __bridge_transfer casts: +(NSString*)webEncodedString:(NSString *)string { CFStringRef retval = CFURLCreateStringByAddingPercentEscapes( NULL, (__bridge CFStringRef)string, NULL, CFSTR( !*'();:@=+$,/?%#[] ), kCFStringEncodingUTF8 ); return CFBridgingRelease(retval); } CFBridgingRelease() balances CFURLCreateString...(). Everything else is ARC's problem as usual. -- Greg Parker gpar...@apple.com Runtime Wrangler ___ 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
Threads and Locking Question
Hi, We are using a third party library that performs tasks asynchronously. This is ok most of the time, but on some occasions I'd like to be able to wait (not on the main thread) until an operation completes, The flow basically goes like this: [theLibraryObject doOperation:myOperation withCompletionBlock:^(void) (ResponseObject* theResponseObject) { //Completion code }]; (The Block syntax is wrong I know, but I don't have the source code in front of me. The doOperation: withCompletionBlock: method just queues the operation and returns. When the operation has finished, it calls the completion block. I'd like to be able to be able to wait in the method that calls doOperation: withCompletionBlock until the completion block is called, something like this: -(void) doAtomicOperation { [self.mLibraryObject doOperation:myOperation withCompletionBlock:^ (void)(ResponseObject* theResponseObject) { //** //**Signal thread that started the operation //** SIGNAL }]; //** //**Wait for Signal before continuing //** WAIT_FOR_SIGNAL } Is there a way of doing this and if so I'd be really grateful if someone could show me the code. I've tried using NSLock and NSConditionalLock etc. but can't get it to work! Thanks a lot All the Best Dave ___ 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: Threads and Locking Question
Should have added, this is for iOS and doesn't have to run on Mac. Hi, We are using a third party library that performs tasks asynchronously. This is ok most of the time, but on some occasions I'd like to be able to wait (not on the main thread) until an operation completes, The flow basically goes like this: [theLibraryObject doOperation:myOperation withCompletionBlock:^(void) (ResponseObject* theResponseObject) { //Completion code }]; (The Block syntax is wrong I know, but I don't have the source code in front of me. The doOperation: withCompletionBlock: method just queues the operation and returns. When the operation has finished, it calls the completion block. I'd like to be able to be able to wait in the method that calls doOperation: withCompletionBlock until the completion block is called, something like this: -(void) doAtomicOperation { [self.mLibraryObject doOperation:myOperation withCompletionBlock:^ (void)(ResponseObject* theResponseObject) { //** //**Signal thread that started the operation //** SIGNAL }]; //** //**Wait for Signal before continuing //** WAIT_FOR_SIGNAL } Is there a way of doing this and if so I'd be really grateful if someone could show me the code. I've tried using NSLock and NSConditionalLock etc. but can't get it to work! Thanks a lot All the Best Dave ___ 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/dave% 40looktowindward.com This email sent to d...@looktowindward.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: Threads and Locking Question
On May 10, 2012, at 3:42 PM, Dave wrote: We are using a third party library that performs tasks asynchronously. This is ok most of the time, but on some occasions I'd like to be able to wait (not on the main thread) until an operation completes, This is usually an indication of a design problem. Is there a way of doing this and if so I'd be really grateful if someone could show me the code. I've tried using NSLock and NSConditionalLock etc. but can't get it to work! NSConditionLock should work. You create it with a condition which you arbitrarily decide means unsignaled. The block locks it (without regard to condition) and then immediately unlocks it in a different condition which you decide means signaled. The code that needs to wait just locks it when the condition is signaled, unlocks it, and releases it. Alternatively, you can use a dispatch_semaphore or dispatch_group for this. Here's an implementation using dispatch_group (written in main, not tested): -(void) doAtomicOperation { dispatch_group_t group = dispatch_group_create(); dispatch_group_enter(group); [self.mLibraryObject doOperation:myOperation withCompletionBlock:^(void)(ResponseObject* theResponseObject) { // Do work dispatch_group_leave(group); }]; //** //**Wait for Signal before continuing //** dispatch_group_wait(group, DISPATCH_TIME_FOREVER); dispatch_release(group); } Regards, Ken ___ 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: Threads and Locking Question
On 5/10/12 1:42 PM, Dave wrote: Hi, We are using a third party library that performs tasks asynchronously. This is ok most of the time, but on some occasions I'd like to be able to wait (not on the main thread) until an operation completes, The doOperation: withCompletionBlock: method just queues the operation and returns. When the operation has finished, it calls the completion block. I'd like to be able to be able to wait in the method that calls doOperation: withCompletionBlock until the completion block is called, something like this: Am I correct in assuming that, given your terminology, you are using an NSOperationQueue? If so, and you have access to the code that's actually adding the operation to the NSOperationQueue, you could revise it to use -addOperations:waitUntilFinished: (passing YES as the second argument). You could of course write a wrapper around this (e.g. -doOperation:withCompletionBlock:waitUntilFinished:). If you are actually using dispatch queues, you could use dispatch_sync() to perform a blocking dispatch. Or are you stuck with the library code (perhaps already compiled) and are looking to do this entirely externally? If so, I see that Ken has already replied with a solution there. -- Conrad Shultz Synthetiq Solutions www.synthetiqsolutions.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: Threads and Locking Question
Hi Ken, Thanks for that I will try it out tomorrow, as an aside, is this ok/ recommended? -(void) someMethod:(NSString*) theParameter { if ([NSThread isMainThread) { [self performSelectorInBackground:@selector(someMethod:) withObject:self]; return; } // Do work } Thanks again Dave On 10 May 2012, at 22:09, Ken Thomases wrote: On May 10, 2012, at 3:42 PM, Dave wrote: We are using a third party library that performs tasks asynchronously. This is ok most of the time, but on some occasions I'd like to be able to wait (not on the main thread) until an operation completes, This is usually an indication of a design problem. Is there a way of doing this and if so I'd be really grateful if someone could show me the code. I've tried using NSLock and NSConditionalLock etc. but can't get it to work! NSConditionLock should work. You create it with a condition which you arbitrarily decide means unsignaled. The block locks it (without regard to condition) and then immediately unlocks it in a different condition which you decide means signaled. The code that needs to wait just locks it when the condition is signaled, unlocks it, and releases it. Alternatively, you can use a dispatch_semaphore or dispatch_group for this. Here's an implementation using dispatch_group (written in main, not tested): -(void) doAtomicOperation { dispatch_group_t group = dispatch_group_create(); dispatch_group_enter(group); [self.mLibraryObject doOperation:myOperation withCompletionBlock:^ (void)(ResponseObject* theResponseObject) { // Do work dispatch_group_leave(group); }]; //** //**Wait for Signal before continuing //** dispatch_group_wait(group, DISPATCH_TIME_FOREVER); dispatch_release(group); } Regards, Ken ___ 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: Threads and Locking Question
On May 10, 2012, at 4:44 PM, Dave wrote: Thanks for that I will try it out tomorrow, as an aside, is this ok/recommended? -(void) someMethod:(NSString*) theParameter { if ([NSThread isMainThread) { [self performSelectorInBackground:@selector(someMethod:) withObject:self]; Presumably, you mean withObject:theParameter. return; } // Do work } As to whether it's OK/recommended, that depends. Why are you doing this? The caller of that method may be very surprised if it's asynchronous. Regards, Ken ___ 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: Threads and Locking Question
On 10 May 2012, at 22:55, Ken Thomases wrote: As to whether it's OK/recommended, that depends. Why are you doing this? The caller of that method may be very surprised if it's asynchronous. No the caller is always expecting it to be ASync. It's just that I have to use a library that uses a delegate Object/selector passed to it and calls it back when the task has finished. This is ok and wanted most of the time,but now we have added a whole load of other functionality and some of it needs to be run in a certain order depending on the responses. Sort of like this myResultObjectA = nil myResultObjectB = nil myResultObjectC = nil myResultObjectD = nil myResultObjectE = nil myResultObjectA = doTaskA if (myResultObjectA.someProperty == 0) myResultObjectB = doTaskBWithSomePropertiesOf: myResultObjectA else if (myResultObjectA.someProperty == 1) myResultObjectC = doTaskCWithSomePropertiesOf: myResultObjectA else ERROR; if (myResultObjectB == nil) myResultObjectD = doTaskDWithSomePropertiesOf: myResultObjectB else myResultObjectD = doTaskDWithSomePropertiesOf: myResultObjectC myResultObjectE = doTaskDWithSomePropertiesOf: myResultObjectA andPropertiesOf: myResultObjectD return myResultObjectE All the doTask methods are ASync, The actual implementation I am working with handles the doTaskXXX calls by passing in Delegate Object and a Completion Selector to the method. When you try to implement the above in that manner , it creates a rats nest of methods which resembles out of control goto's! It makes more sense to be able to have all the code in one method. Cheers Dave ___ 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
First Responder
I have a menu item connected to an action in First Responder; The action exists in an NSView subclass. The subclass implements acceptsFirstResonder and return YES. The subclass implements validateMenuItem and return YES; When the menu displays the menu item is disabled (set to enabled in IB). Is this not the proper implementation? -koko ___ 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: First Responder
On Thu, May 10, 2012 at 6:24 PM, koko k...@highrolls.net wrote: I have a menu item connected to an action in First Responder; The action exists in an NSView subclass. The subclass implements acceptsFirstResonder and return YES. The subclass implements validateMenuItem and return YES; When the menu displays the menu item is disabled (set to enabled in IB). Is this not the proper implementation? Does your subclass implement the action that the menu item is looking for? Your view subclass won't be chosen as the first responder if it doesn't implement the action. ___ 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: First Responder
I have had this happen when I have forgotten to declare my action method in the public header. Erik Stainsby erik.stain...@roaringsky.ca - On 2012-05-10, at 4:24 PM, koko wrote: I have a menu item connected to an action in First Responder; The action exists in an NSView subclass. The subclass implements acceptsFirstResonder and return YES. The subclass implements validateMenuItem and return YES; When the menu displays the menu item is disabled (set to enabled in IB). Is this not the proper implementation? -koko ___ 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/erik.stainsby%40roaringsky.ca This email sent to erik.stain...@roaringsky.ca ___ 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: First Responder
On May 10, 2012, at 6:05 PM, Stephen J. Butler wrote: Does your subclass implement the action that the menu item is looking for? Your view subclass won't be chosen as the first responder if it doesn't implement the action Yes, the subclass implements the action. ___ 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: First Responder
On May 10, 2012, at 6:05 PM, Erik Stainsby wrote: I have had this happen when I have forgotten to declare my action method in the public header. The action is declared in the subclass header. ___ 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: First Responder
Could you please paste the a copy of the method in a message? It is far easier to help you debug code which we can see than a description of something we cannot see. Erik Stainsby erik.stain...@roaringsky.ca - On 2012-05-10, at 5:07 PM, koko wrote: On May 10, 2012, at 6:05 PM, Erik Stainsby wrote: I have had this happen when I have forgotten to declare my action method in the public header. The action is declared in the subclass header. ___ 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: First Responder
On 5/10/12 4:24 PM, koko wrote: I have a menu item connected to an action in First Responder; The action exists in an NSView subclass. The subclass implements acceptsFirstResonder and return YES. The subclass implements validateMenuItem and return YES; When the menu displays the menu item is disabled (set to enabled in IB). Is this not the proper implementation? Let's cut to something more basic: is your view ACTUALLY in the responder chain? Since you apparently are expecting it to become firstResponder, do you actually make sure that it does (for example, by sending its window -makeFirstResponder: or marking it as the window's initialFirstResponder)? Remember that overriding acceptsFirstResponder does not magically put a view in the responder chain. (In addition to -makeFirstResponder: the view could also of course acquire first responder status in the usual manner, by user interaction.) -- Conrad Shultz Synthetiq Solutions www.synthetiqsolutions.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: First Responder
koko wrote: I have a menu item connected to an action in First Responder; The action exists in an NSView subclass. The subclass implements acceptsFirstResonder and return YES. The subclass implements validateMenuItem and return YES; When the menu displays the menu item is disabled (set to enabled in IB). Is this not the proper implementation? Absent from this narrative: Any indication that you have reason to believe your view has actually *become* the first responder. ___ 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
Calculating layer's CATransform3D transformations
Hello, the questions are: 1. What equations are used to transform CALayers in 3D space and project their 2d point {x, y, z} to the 2D surface {x, y} ? All equations that I've found to project 3D points onto 2D space aren't the same with what CALayers use. My solve is to get one coordinate {x, y} where -1 x 1 and -1 y 1 and, using 3D affine transforms, apply layer's transforms to point and then make it 2D: CGFloat pointX = transformPCM.m11 * point.m1 + transformPCM.m12 * point.m2 + transformPCM.m13 * point.m3 + transformPCM.m14 * point.m4; CGFloat pointY = transformPCM.m21 * point.m1 + transformPCM.m22 * point.m2 + transformPCM.m23 * point.m3 + transformPCM.m24 * point.m4; CGFloat pointZ = transformPCM.m31 * point.m1 + transformPCM.m32 * point.m2 + transformPCM.m33 * point.m3 + transformPCM.m34 * point.m4; CGFloat newX = (pointX) / (pointZ); CGFloat newY = (pointY) / (pointZ); 2. What is m34 parameter of CATransform3D struct? I understood that it is for translating point by z axis just like m24 for y axis and m14 for x axis, BUT!... in equations from above it doesn't make any sense, whereas CALayer's transformation is being changed according to zDistance (m34 = 1 / (-zDistance) as Apple Core Animation documentation says) Any advice would be helpful) Thank you, Kirill ___ 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
architectures that prevent freezing
. in a pre-emptive OS there should be no freezing; given the new concurrency model that includes the use of the graphics processor GPU to do the system's non-graphics processing, my current guess is that the freezes happen when something goes wrong in the GPU, and the CPU is just waiting forever . . the CPU needs to have some way of getting control back, and sending an exception message to any of the processes that were affected by the hung-up GPU . . could any of Apple's developers correct this theory or comment on it ? ___ 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