Re: Issue with -[NSOutlineView autosaveExpandedItems] - SOLVED
On Jul 11, 2014, at 4:45 PM, Gary L. Wade garyw...@desisoftsystems.com wrote: Sounds like it’s time to update Cocoa Recipes to a 3rd edition to fully share these nuggets. ;) That's been suggested from time to time, but I'm afraid I don't have another book in me. -- Bill Cheeseman - b...@cheeseman.name ___ 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
KVC, binding multiple properties, top level object
My object layout looks like: -MyObject (custom NSObject) ---someProperty (Custom NSObject) --propertyA (NSNumber) --propertyB (NSNumber) --propertyC (NSNumber) Properties A, B and C use a binding to connect them to a user interface item with something like: Bind to MyObject with key path someProperty.propertyA If I have all three properties hooked up like this, it is easy to change the value of one of them with [someProperty setPropertyA:newValue] which updates in a KVC-friendly way and everything is good. However, I would like to replace the entire someProperty object with a new object of the same class and have all the lower level bindings see the change in a KVC way. Will doing [myObject setSomeProperty:newProperty] issue all the right KVC notifications so the bound objects update their values? I just need to update the upper-level object which has lots of bound properties... Without having to update each property individually. Thanks, Trygve ___ 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
NSAccessibilityPressAction on NSMenuItem
Hi, I'm trying to perform an NSAccessibilityPressAction on a NSMenuItem in my own app. Currently I've this: [[[NSApplication sharedApplication].menu itemAtIndex:2] accessibilityPerformAction:NSAccessibilityPressAction]; I get back an unrecognised selector sent message. When I try to traverse the accessibility objects using [[NSApplication sharedApplication] accessibilityAttributeValue:NSAccessibilityMenuBarAttribute]; I get back a plain NSMenu, to which I also can not send any accessibility messages. The inspector on the other hand seems to be able to get to an AXMenuItem and send the press action to it. How do I get that AXMenuItem? Or how can I send the press action to a menu item? Thanks in advance. Kind regards, Remco Poelstra ___ 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: KVC, binding multiple properties, top level object
On Jul 12, 2014, at 7:05 AM, Trygve Inda cocoa...@xericdesign.com wrote: My object layout looks like: -MyObject (custom NSObject) ---someProperty (Custom NSObject) --propertyA (NSNumber) --propertyB (NSNumber) --propertyC (NSNumber) Properties A, B and C use a binding to connect them to a user interface item with something like: Bind to MyObject with key path someProperty.propertyA If I have all three properties hooked up like this, it is easy to change the value of one of them with [someProperty setPropertyA:newValue] which updates in a KVC-friendly way and everything is good. However, I would like to replace the entire someProperty object with a new object of the same class and have all the lower level bindings see the change in a KVC way. Will doing [myObject setSomeProperty:newProperty] issue all the right KVC notifications so the bound objects update their values? You're actually concerned about KVO here. That said, the main way to achieve KVO-compliance for a property is to use KVC-compliant accessor names and then use those accessors when modifying the property. Anyway, the answer is yes, all of the observers will update properly. KVO-compliance need only be implemented on a local, property-by-property basis. It's not necessary to take a global perspective. In general, an object wouldn't know which of its properties were being observed and definitely not which are being observed through. So, you only need to ensure that you're updating someProperty in a KVO-compliant manner and KVO takes care of the rest. (And, of course, that propertyA, etc., are also updated in a KVO-compliant manner.) 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: KVC, binding multiple properties, top level object
On 12 Jul 2014, at 10:05 pm, Trygve Inda cocoa...@xericdesign.com wrote: ---someProperty (Custom NSObject) --propertyA (NSNumber) --propertyB (NSNumber) --propertyC (NSNumber) Properties A, B and C use a binding to connect them to a user interface item with something like: Bind to MyObject with key path someProperty.propertyA Just as a matter of interest, why do you decalre these subproperties as NSNumber types? Is there a reason you can't just make them the native scalar types they wrap (e.g. integer, float)? KVC/KVO automatically wraps scalar values with NSNumber or NSValue to pass them around through bindings, so you don't have to concern yourself with it. Usually, code is clearer if properties are declared as the native types. If you make them NSNumbers, how will you detect or prevent a value of the wrong type being passed? --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: Converting database to Core Data
Perhaps I don't see the problem but what is preventing you from creating the second inverse relationship? Op 10 jul 2014, om 22:00 heeft William Squires het volgende geschreven: I'm trying to convert the following. I have two tables in a database, TransactionEntry, and ReasonCode. A TransactionEntry record is just a posting from a POS (Point-of-Sale) terminal, and has these fields (of interest): Table (TransactionEntry) ID As Int32 PrimaryReasonCode As Int32 // both of these link to ReasonCode.ID SecondaryReasonCode As Int32 ... and a ReasonCode record is used when a certain types of transactions occur, such as POSItemReturned, POSItemVoided, POSCommError, and a few others. Table (ReasonCode) ID As Int32 Description As Varchar(50) ReasonCode As Int16 // just an enum ... All would be good and well if the TransactionEntry table had only one reference (.PrimaryReasonCode) to the ReasonCode table, but some transactions (such as a voided item) require the manager to fill in both the primary and secondary reason codes. I can create the entities, and replace the Int32 record numbers/IDs with a relationship. I create the relationship in entity TransactionEntry and set it to ReasonCode, leaving the inverse relationship to none for now. I then create an inverse relationship in entity ReasonCode to refer back to TransactionEntry. Now I can create the inverse relationships in both directions. 1:1 for TransactionEntry - ReasonCode, and 1:many for ReasonCode - TransactionEntry. All okay so far. Primary ReasonCode records (entities) are re-used to save memory, and the .Description fields are pre-set to values such as, return item, wrong key hit, cc reader not working, etc... Secondary ReasonCode entities are (usually) created on-demand from the POS terminal when the manager logs in. A few are re-used, but mostly new entities are created. The problem now comes when I try to create the same relationships from TransactionEntry entities to ReasonCode entities for the secondary reason code records (entities), since it won't let me make both inverse relationships 1:many from ReasonCode back to TransactionEntry. Is this a limitation of CoreData? Or is there a way around this? Can I ignore Xcode's warnings about not having inverse relationships, and simply set the inverse relationships from the TransactionEntry entity(ies) to the ReasonCode Entity to none, and simply get rid of the inverse relationships in the ReasonCode entity? Please help! :) ___ 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/willeke2007%40gmail.com This email sent to willeke2...@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: Unwanted enclosingScrollView
I have just discovered that overriding enclosingScrollView and returning nil, doesn't let me longer see and edit the paragraph demiliters and tabs on the ruler view. In facts, when the user is editing the textView, the page's scrolling view should display the paragraph delimiters and tabs on its ruler view. If I return nil from the textView's enclosingScrollView method, the pragraph's delimiters and tabs don't show up anymore. So, if I don't override the textView's enclosingScrollView method, when I resize the textView by dragging its handles, the page's scrollingView scrolls in an unexpected way. If I ovveride enclosingScrollView and return nil, I get no pragraph's delimiters and tabs. I'm puzzled. Any solution? Regards -- Leonardo Da: Kyle Sluder k...@ksluder.com Data: Wed, 25 Jun 2014 09:57:06 -0500 A: Leonardo mac.iphone@gmail.com Cc: cocoa-dev@lists.apple.com cocoa-dev@lists.apple.com Oggetto: Re: Unwanted enclosingScrollView On Jun 25, 2014, at 9:50 AM, Leonardo mac.iphone@gmail.com wrote: I have a page which is an NSView within a NSScrollView. I put a NSTextView just within the page, without its scrollView. NSScrollView (page's scrollView) NSClipView NSView (documentView - my page) NSTextView (my textView Box) So I have just discovered that the [textView enclosingScrollView] *becames* the page's scrollView. Thus, when I resize the textView, its enclosingScrollView gets scrolled to the origin. And my page scrolls inopportunely. How to get rid of this behavior? Have you tried subclassing NSTextView and overriding -enclosingScrollView to return nil? --Kyle Sluder ___ 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
having both cell based and view based outline views in one project
Hi, I had one (set cell-based in IB) outline view in my project using custom cell for one table Column (identifier : “Description”). And it was working fine with my AppDelegate implementing the required datasource and some delegate methods. I added another (set view-based in IB) outline view and I am returning custom views in the following method (in AppDelegate): - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { NSString *identifier = [tableColumn identifier]; if ([outlineView isEqualTo:outlineViewThumbs]) { if ([identifier isEqualToString:COLUMN_ID_DESC]) {// having only one table column return [item cellView]; } } return nil; } This view-based outline view is working as expected, but the earlier cell-based outline is now showing empty rows (yes, it does populate as is evident from the vertical scroller and clicking also selects the row). Adding a breakpoint in the above method, I can see it being called by cell-based outline view, and in this case this method returns nil. And the outlineView: objectValueForTableColumn: item: method doesn’t get called. If I comment the last line in above method and return nothing for the cell-based outline view, the outlineView: objectValueForTableColumn: item: is called after the above method, but it leads to crash at another place in code where I’m doing [tabView display];. This tabView contains both the outline views in separate tabs. How to tackle it? Do I need to use two separate classes for datasource and delegate for the two outline views? Thanks, Navneet ___ 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: having both cell based and view based outline views in one project
On Jul 12, 2014, at 9:20 AM, Navneet Kumar wrote: I had one (set cell-based in IB) outline view in my project using custom cell for one table Column (identifier : “Description”). And it was working fine with my AppDelegate implementing the required datasource and some delegate methods. I added another (set view-based in IB) outline view and I am returning custom views in the following method (in AppDelegate): - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { NSString *identifier = [tableColumn identifier]; if ([outlineView isEqualTo:outlineViewThumbs]) { if ([identifier isEqualToString:COLUMN_ID_DESC]) {// having only one table column return [item cellView]; } } return nil; } This view-based outline view is working as expected, but the earlier cell-based outline is now showing empty rows (yes, it does populate as is evident from the vertical scroller and clicking also selects the row). Adding a breakpoint in the above method, I can see it being called by cell-based outline view, and in this case this method returns nil. And the outlineView: objectValueForTableColumn: item: method doesn’t get called. If I comment the last line in above method and return nothing for the cell-based outline view, the outlineView: objectValueForTableColumn: item: is called after the above method, but it leads to crash at another place in code where I’m doing [tabView display];. This tabView contains both the outline views in separate tabs. How to tackle it? Do I need to use two separate classes for datasource and delegate for the two outline views? Most likely. As far as I can tell, there is no public property that tells an NSTableView whether it is cell-based or view-based, so I am not surprised that it determines this based on implemented delegate methods. Alternatively, since cell-based table views are being deprecated, you could convert your cell-based to view-based and then your app will have some future-proofing. HTH, Keary Suska Esoteritech, Inc. Demystifying technology for your home or business ___ 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
[NSMutableData resetDataRangeTo:(NSRange)range];
Basically what I would like is an NSMutableData method like this: - (void)resetDataRangeTo:(NSRange)range Parameters range The range within the contents of the receiver to be considered the new contents. But, since that doesn't exist yet, is it safe to shift the contents in place of an NSMutableData? I'm trying to avoid having to copy the contents, which is 1MB. In this example, I want to remove the leading 1024 bytes in a large NSMutableData: NSMutableData *bigData = ... // (approx 1MB of data); UInt64 byte_shift = 1024;// skip over first 1024 bytes UInt64 new_length = bigMutData.length-byte_shift; NSRange moveRange = NSMakeRange(0,new_length); [bigMutData replaceBytesInRange:moveRange withBytes:bigMutData.bytes+1024 length:new_length]; [bigMutData setLength:new_length]; -Carl ___ 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: having both cell based and view based outline views in one project
Hi, Thanks for the valuable insight. For now I'll try separating the data source delegate, for the two outline views, just to save time. And will switch to view based, in due time. Thanks very much. Navneet Sent from my iPhone On 12-Jul-2014, at 9:02 pm, Keary Suska cocoa-...@esoteritech.com wrote: On Jul 12, 2014, at 9:20 AM, Navneet Kumar wrote: I had one (set cell-based in IB) outline view in my project using custom cell for one table Column (identifier : “Description”). And it was working fine with my AppDelegate implementing the required datasource and some delegate methods. I added another (set view-based in IB) outline view and I am returning custom views in the following method (in AppDelegate): - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { NSString *identifier = [tableColumn identifier]; if ([outlineView isEqualTo:outlineViewThumbs]) { if ([identifier isEqualToString:COLUMN_ID_DESC]) {// having only one table column return [item cellView]; } } return nil; } This view-based outline view is working as expected, but the earlier cell-based outline is now showing empty rows (yes, it does populate as is evident from the vertical scroller and clicking also selects the row). Adding a breakpoint in the above method, I can see it being called by cell-based outline view, and in this case this method returns nil. And the outlineView: objectValueForTableColumn: item: method doesn’t get called. If I comment the last line in above method and return nothing for the cell-based outline view, the outlineView: objectValueForTableColumn: item: is called after the above method, but it leads to crash at another place in code where I’m doing [tabView display];. This tabView contains both the outline views in separate tabs. How to tackle it? Do I need to use two separate classes for datasource and delegate for the two outline views? Most likely. As far as I can tell, there is no public property that tells an NSTableView whether it is cell-based or view-based, so I am not surprised that it determines this based on implemented delegate methods. Alternatively, since cell-based table views are being deprecated, you could convert your cell-based to view-based and then your app will have some future-proofing. HTH, Keary Suska Esoteritech, Inc. Demystifying technology for your home or business ___ 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: Issue with -[NSOutlineView autosaveExpandedItems] - SOLVED
On Jul 11, 2014, at 4:29 PM, Bill Cheeseman wjcheese...@gmail.com wrote: And I've discovered another difficulty, although I think I can handle it. When you add, remove or edit a row that is a child of an expanded parent item, AppKit does not automatically call -outlineView:persistentObjectForItem: to update the autosaved data for the parent. Therefore, when you quit and relaunch the application, the new expanded parent item does not match the old expanded parent item autosaved in user defaults, and -outlineView:itemForPersistentObject: does not find a match. As a result, it returns nil and AppKit collapses the parent item on relaunch. The same thing will happen to an edited row if it was expanded before being edited. I think this issue is inherent in the autosave mechanism as Apple has implemented it. A third way to handle it would be to go the autosaved UUID route. The autosaved UUIDs would still be correct after quit and relaunch, and you could retrieve the revised items directly from the datasource in your implementation of the -outlineView:itemForPersistentObject: method. The datasource is always up to date by definition, and you would never encounter a mismatch. I fear the third approach might be the best. I hate to have to add a UUID to every item in the datasource, but Apple does provide a Cocoa UUID class to make it easy. I have now added a UUID identifier field to each dictionary in my datasource array. Some of the dictionaries have nested arrays with still more dictionaries, and all of those dictionaries now also have UUID identifier fields. The nesting levels have no limit. The autosaveExpandedItems mechanism is now working perfectly. In -outlineView:persistentObjectForItem:, I simply archive the UUID string. The interesting method is -outlineView:itemForPersistentObject:. It unarchives the archived UUID string. Then it uses recursive blocks to search the data source array through all nested levels until it finds the item with the same UUID identifier and returns it. Here is the method: - (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object { // Datasource method per NSOutlineViewDataSource formal protocol. Required if using autosaveExpandedItems. Called when application launches, once for each item in the autosaved array in the user defaults preferences file. AppKit calls this before -awakeFromNib, so the source list data source must be populated in the designated initializer. NSString *identifier = [NSKeyedUnarchiver unarchiveObjectWithData:object]; __block id returnItem = nil; __block void (^findItemForIdentifierInArray)(NSArray *) = ^(NSArray *contents) { [contents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([[obj objectForKey:ID_KEY] isEqualToString:identifier]) { returnItem = obj; *stop = YES; } id subarray = [obj objectForKey:CONTENTS_KEY]; if (subarray) { findItemForIdentifierInArray(subarray); // recursive } }]; }; findItemForIdentifierInArray([self sourceListContents]); return returnItem; } The only remaining problem is that the recursive call to findItemForIdentifierInArray() is flagged with a warning that it is likely to lead to retain cycles, hence leaks. I don't know how to fix this, despite some hours of online searching. Can anybody with greater knowledge of blocks help me on this? -- Bill Cheeseman - b...@cheeseman.name ___ 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: [NSMutableData resetDataRangeTo:(NSRange)range];
don’t you just want: [bigData replaceBytesInRange:NSMakeRange(0, 1024) withBytes:NULL length:0]; ?? I am sure NSMutableData is well optimized for shunting its contents around internally. Matt On 12 Jul 2014, at 20:36, Carl Hoefs newsli...@autonomy.caltech.edu wrote: Basically what I would like is an NSMutableData method like this: - (void)resetDataRangeTo:(NSRange)range Parameters range The range within the contents of the receiver to be considered the new contents. But, since that doesn't exist yet, is it safe to shift the contents in place of an NSMutableData? I'm trying to avoid having to copy the contents, which is 1MB. In this example, I want to remove the leading 1024 bytes in a large NSMutableData: NSMutableData *bigData = ... // (approx 1MB of data); UInt64 byte_shift = 1024;// skip over first 1024 bytes UInt64 new_length = bigMutData.length-byte_shift; NSRange moveRange = NSMakeRange(0,new_length); [bigMutData replaceBytesInRange:moveRange withBytes:bigMutData.bytes+1024 length:new_length]; [bigMutData setLength:new_length]; -Carl ___ 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/devlists.mg%40googlemail.com This email sent to devlists...@googlemail.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: having both cell based and view based outline views in one project
On 13 Jul 2014, at 1:32 am, Keary Suska cocoa-...@esoteritech.com wrote: As far as I can tell, there is no public property that tells an NSTableView whether it is cell-based or view-based Yet there's a popup in IB (the very first one), so it's presumably doing something. -- Shane Stanley sstan...@myriad-com.com.au www.macosxautomation.com/applescript/apps/ ___ 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: Issue with -[NSOutlineView autosaveExpandedItems] - SOLVED
On Jul 12, 2014, at 13:50 , Bill Cheeseman wjcheese...@gmail.com wrote: __block id returnItem = nil; __block void (^findItemForIdentifierInArray)(NSArray *) = ^(NSArray *contents) { [contents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([[obj objectForKey:ID_KEY] isEqualToString:identifier]) { returnItem = obj; *stop = YES; } id subarray = [obj objectForKey:CONTENTS_KEY]; if (subarray) { findItemForIdentifierInArray(subarray); // recursive } }]; }; findItemForIdentifierInArray([self sourceListContents]); return returnItem; } The only remaining problem is that the recursive call to findItemForIdentifierInArray() is flagged with a warning that it is likely to lead to retain cycles, hence leaks. I dunno, this sort of thing makes my head hurt too. But I can’t see any downside to changing this to use a private method and a for loop inside it, other than having to think of a private method name. ___ 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: [NSMutableData resetDataRangeTo:(NSRange)range];
On Jul 12, 2014, at 1:51 PM, Matt Gough devlists...@gmail.com wrote: [bigData replaceBytesInRange:NSMakeRange(0, 1024) withBytes:NULL length:0]; Wow, I would never have thought to do that! Works perfectly! Thx, -Carl ___ 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: Issue with -[NSOutlineView autosaveExpandedItems] - SOLVED
On Jul 12, 2014, at 3:50 PM, Bill Cheeseman wjcheese...@gmail.com wrote: The interesting method is -outlineView:itemForPersistentObject:. It unarchives the archived UUID string. Then it uses recursive blocks to search the data source array through all nested levels until it finds the item with the same UUID identifier and returns it. Here is the method: - (id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:(id)object { // Datasource method per NSOutlineViewDataSource formal protocol. Required if using autosaveExpandedItems. Called when application launches, once for each item in the autosaved array in the user defaults preferences file. AppKit calls this before -awakeFromNib, so the source list data source must be populated in the designated initializer. NSString *identifier = [NSKeyedUnarchiver unarchiveObjectWithData:object]; __block id returnItem = nil; __block void (^findItemForIdentifierInArray)(NSArray *) = ^(NSArray *contents) { [contents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([[obj objectForKey:ID_KEY] isEqualToString:identifier]) { returnItem = obj; *stop = YES; } id subarray = [obj objectForKey:CONTENTS_KEY]; if (subarray) { findItemForIdentifierInArray(subarray); // recursive } }]; }; findItemForIdentifierInArray([self sourceListContents]); return returnItem; } The only remaining problem is that the recursive call to findItemForIdentifierInArray() is flagged with a warning that it is likely to lead to retain cycles, hence leaks. I don't know how to fix this, despite some hours of online searching. Can anybody with greater knowledge of blocks help me on this? You could do it this way: __block void (^__unsafe_unretained innerFindItemForIdentifierInArray)(NSArray *); __block void (^findItemForIdentifierInArray)(NSArray *) = ^(NSArray *contents) { [contents enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([[obj objectForKey:ID_KEY] isEqualToString:identifier]) { returnItem = obj; *stop = YES; } id subarray = [obj objectForKey:CONTENTS_KEY]; if (subarray) { innerFindItemForIdentifierInArray(subarray); // recursive } }]; }; innerFindItemForIdentifierInArray = findItemForIdentifierInArray; This still has a problem. It doesn't stop when you intend it to. Any given -enumerate... call will stop if it directly finds the match, but an outer call won't. You could add if (returnItem) *stop = YES; after the recursive call. Or, you could pass the stop variable into the recursive call so that an inner call can set it. It seems like your contents are dictionaries. It might be better to make them a custom class with the appropriate properties. Then, you could add a method like: - (TheClass*) descendantWithIdentifier:(NSString*)identifier { if ([self.identifier isEqualToString:identifier]) return self; for (TheClass* child in self.children) { TheClass* match = [child descendantWithIdentifier:identifier]; if (match) return match; } return nil; } 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: having both cell based and view based outline views in one project
On Jul 12, 2014, at 4:47 PM, Shane Stanley sstan...@myriad-com.com.au wrote: On 13 Jul 2014, at 1:32 am, Keary Suska cocoa-...@esoteritech.com wrote: As far as I can tell, there is no public property that tells an NSTableView whether it is cell-based or view-based Yet there's a popup in IB (the very first one), so it's presumably doing something. It's changing the prototype objects. 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: having both cell based and view based outline views in one project
On 13 Jul 2014, at 7:58 am, Ken Thomases k...@codeweavers.com wrote: It's changing the prototype objects. Makes sense, thanks. On my first try I spent ages trying to delete the old text cell, until I checked the example again... -- Shane Stanley sstan...@myriad-com.com.au www.macosxautomation.com/applescript/apps/ ___ 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: [NSMutableData resetDataRangeTo:(NSRange)range];
On Saturday, July 12, 2014, Carl Hoefs newsli...@autonomy.caltech.edu wrote: On Jul 12, 2014, at 1:51 PM, Matt Gough devlists...@gmail.com javascript:; wrote: [bigData replaceBytesInRange:NSMakeRange(0, 1024) withBytes:NULL length:0]; Wow, I would never have thought to do that! Works perfectly! You could also declare a category on NSMutableData to call that function in a way that makes sense to you. Thx, -Carl ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com javascript:;) 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/sevenbitstech%40gmail.com This email sent to sevenbitst...@gmail.com javascript:; ___ 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