Re: Swift Compiler Bug?

2014-09-15 Thread Charles Jenkins
Duhh! I have created dictionaries already—there’s a sample one for 
testing in my app already—but the syntax of that prototype went right over my 
head. I’m accustomed to JSON and Python’s use of braces to declare 
dictionaries, and I was so fully convinced the variable was an array that I 
misunderstood it as NSObject: [AnyObject] every time I saw and typed it.  

Ordinarily I’m not quite this dumb, but as you can see I’m not completely used 
to the syntax yet. I wish Apple had chosen braces, but perhaps that would have 
created needless confusion with closures.

Thank you to everyone who answered my silly question! :-)

--  

Charles


On Sunday, September 14, 2014 at 23:04, Quincey Morris wrote:

> On Sep 14, 2014, at 19:47 , Charles Jenkins  (mailto:cejw...@gmail.com)> wrote:
>  
> >  let noWrappers: [AnyObject] = []
> >  self.theFileWrapper = NSFileWrapper( directoryWithFileWrappers: 
> > noWrappers )
>  
> > When I start typing “directoryWithFileWrappers,” Xcode displays its 
> > suggestion list showing the prototype:
> >  
> > NSFileWrapper( directoryWithFileWrappers: [NSObject : AnyObject] )
>  
> > I think I could send nil instead of bothering to create an empty array, but 
> > whatever.
>  
> No, the parameter isn’t an optional type, so you can’t pass nil.
> > Anyway, Xcode gives me the prototype which agrees with Apple’s 
> > documentation, and I code according to it. Then Xcode marks the line as an 
> > error: “Missing argument for parameter ‘options’ in call,” and my project 
> > won’t build.
> >  
> > Is there an error in my code, or is this a problem I should report to 
> > Apple? And in the latter case, what’s the best way?
>  
> The parameter is a *dictionary*, not an array. IIRC you can specify an empty 
> dictionary as ‘[:]’, so there’s no real need for a supplementary variable.
>  
> If that’s the error that’s being reported on, then it’s being mis-reported. 
> That’s probably worth a bug report.
>  

___

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

Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Jerry Krinock
OS X app has an NSOutlineView with a data source.  Clicking on a disclosure 
triangle to expand an item that has 13,000 children causes its data source to 
immediately receive -outlineView:child:ofItem: 13,000 times, on the main 
thread.  The app presents a beachball until it’s over, which is unacceptable.

I think that Cocoa should know how many rows can fit in the window, stop 
beachballing and redraw after these two dozen or so rows plus a little more 
have been fetched, as UIFetchedResultsController does with its batch size in 
iOS.

The observed behavior seems to be at odds with what I read in the AppKit 
Release Notes for Yosemite:

"Normally, a table view will only keep around a subset of the total number of 
rows potentially available (in general, this is limited to the visible region, 
plus some overdrawn allowance for responsive scrolling).”

It would be nice!  Is that correct?  If so, how might my outline view be 
abnormal?  My data source is backed by Core Data, but I don’t think that 
matters to this issue.  Below is a call stack of how my data source gets a 
typical one of those 13,000 messages.

Thanks,

Jerry

#0   in -[JerrysDataSource outlineView:child:ofItem:] at 
/path/to/JerrysDataSource.m
#1   in loadItemEntryLazyInfoIfNecessary ()
#2   in -[NSOutlineView 
_rowEntryForChild:ofParent:requiredRowEntryLoadMask:] ()
#3   in -[NSOutlineView 
_expandItemEntryChildren:atStartLevel:expandChildren:andInvalidate:] ()
#4   in -[NSOutlineView _expandItemEntry:expandChildren:startLevel:] ()
#5   in -[NSOutlineView _batchExpandItemsWithItemEntries:expandChildren:] ()
#6   in -[NSOutlineView expandItem:expandChildren:] ()
#7   in -[NSOutlineView 
_doUserExpandOrCollapseOfItem:isExpand:optionKeyWasDown:] ()
#8   in -[NSOutlineView mouseTracker:didStopTrackingWithEvent:] ()
#9   in -[NSMouseTracker stopTrackingWithEvent:] ()
#10  in -[NSMouseTracker trackWithEvent:inView:withDelegate:] ()
#11  in -[NSOutlineView mouseDown:] ()
#12  in -[JerrysOutlineView mouseDown:] at /path/to/JerrysOutlineView.m

I presume the bottom line #12 is the mouse click on the disclosure triangle.
___

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: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Kyle Sluder
On Mon, Sep 15, 2014, at 01:52 PM, Jerry Krinock wrote:
> 
> It would be nice!  Is that correct?  If so, how might my outline view be
> abnormal?  My data source is backed by Core Data, but I don’t think that
> matters to this issue.  Below is a call stack of how my data source gets
> a typical one of those 13,000 messages.

Are you using a view-based outline view?

Does your outline view have constant row heights, or are you
implementing -tableView:heightOfRow:?

--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

Re: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Jerry Krinock

On 2014 Sep 15, at 11:56, Kyle Sluder  wrote:

> Are you using a view-based outline view?

No.  It is cell-based.  App currently runs in Mac OS X 10.6.

> Does your outline view have constant row heights, or are you
> implementing -tableView:heightOfRow:?

Constant row heights.  I am not implementing -tableView:heightOfRow: for this 
outline view.


___

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: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Kyle Sluder

On Sep 15, 2014, at 12:31 PM, Jerry Krinock  wrote:
> 
> 
>> On 2014 Sep 15, at 11:56, Kyle Sluder  wrote:
>> 
>> Are you using a view-based outline view?
> 
> No.  It is cell-based.  App currently runs in Mac OS X 10.6.

Can’t very well keep “only the onscreen views” if the table isn’t view-based…

--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

Re: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Jerry Krinock

On 2014 Sep 15, at 12:35, Kyle Sluder  wrote:

> Can’t very well keep “only the onscreen views” if the table isn’t view-based…

Makes sense!  Are you implying that lazy loading is a side benefit of 
view-based tables, and hence that this performance bottleneck is a legacy that 
I could fix by dropping support for 10.6 and updating to a view-based outline?


___

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: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Ken Thomases
On Sep 15, 2014, at 1:52 PM, Jerry Krinock  wrote:

> OS X app has an NSOutlineView with a data source.  Clicking on a disclosure 
> triangle to expand an item that has 13,000 children causes its data source to 
> immediately receive -outlineView:child:ofItem: 13,000 times, on the main 
> thread.  The app presents a beachball until it’s over, which is unacceptable.

Check the places where you can control how the outline view sizes the columns.  
In particular, from the docs for -[NSOutlineViewDelegate 
outlineView:sizeToFitWidthOfColumn:]:

"By default, NSOutlineView iterates every row in the table, accesses a cell via 
preparedCellAtColumn:row:, and requests the cellSize to find the appropriate 
largest width to use.

For accurate results and performance, it is recommended that this method is 
implemented when using large tables. By default, large tables use a monte carlo 
simulation instead of iterating every row."

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: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Ken Thomases
On Sep 15, 2014, at 2:46 PM, Jerry Krinock  wrote:

> On 2014 Sep 15, at 12:35, Kyle Sluder  wrote:
> 
>> Can’t very well keep “only the onscreen views” if the table isn’t view-based…
> 
> Makes sense!  Are you implying that lazy loading is a side benefit of 
> view-based tables, and hence that this performance bottleneck is a legacy 
> that I could fix by dropping support for 10.6 and updating to a view-based 
> outline?

I don't think that's the case.  One of the rationales for using NSCell and 
subclasses was that they were lightweight.  Switching to views is somewhat 
heavier-weight but enabled by much faster computers since the old days.  In 
other words, the old NSCell-based approach was, if anything, even more amenable 
to lazy loading.

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

Binding Exception

2014-09-15 Thread Richard Charles
I have a binding that throws an Objective-C exception but the console displays 
no output and the application does not crash but rather the application runs 
fine. Enabling NSBindingDebugLogLevel 1 does not help, the console still 
displays nothing. I am using Xcode 5.1.1 with the All Exceptions breakpoint 
enabled.

 [self bind:@"allowSelection"
   toObject:_customView.window.windowController
withKeyPath:@“widgetControllerManager.activeWidgetController.allowSelection"
options:nil];

The stack trace looks like this.

#0 0x7fff909f0e4a in objc_exception_throw ()
#1 0x7fff8a3f710c in +[NSException raise:format:] ()
#2 0x7fff94b152a7 in -[NSObject(NSKeyValueCoding) setNilValueForKey:] ()
#3 0x7fff94a4472e in -[NSObject(NSKeyValueCoding) setValue:forKey:] ()
#4 0x7fff88549f0d in -[NSObjectParameterBinder 
_updateObject:observedController:observedKeyPath:context:] ()
#5 0x7fff88540f08 in -[NSObject(NSKeyValueBindingCreation) 
bind:toObject:withKeyPath:options:] ()

This application contains lots of programatic bindings similar to this one. 
However this is the only one which throws an exception.

Should I be concerned about this?

Is there anyway to debug this?

Thanks,
Richard Charles
___

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: Binding Exception

2014-09-15 Thread Keary Suska

On Sep 15, 2014, at 2:42 PM, Richard Charles  wrote:

> I have a binding that throws an Objective-C exception but the console 
> displays no output and the application does not crash but rather the 
> application runs fine. Enabling NSBindingDebugLogLevel 1 does not help, the 
> console still displays nothing. I am using Xcode 5.1.1 with the All 
> Exceptions breakpoint enabled.
> 
> [self bind:@"allowSelection"
>   toObject:_customView.window.windowController
>
> withKeyPath:@“widgetControllerManager.activeWidgetController.allowSelection"
>options:nil];
> 
> The stack trace looks like this.
> 
> #0 0x7fff909f0e4a in objc_exception_throw ()
> #1 0x7fff8a3f710c in +[NSException raise:format:] ()
> #2 0x7fff94b152a7 in -[NSObject(NSKeyValueCoding) setNilValueForKey:] ()
> #3 0x7fff94a4472e in -[NSObject(NSKeyValueCoding) setValue:forKey:] ()
> #4 0x7fff88549f0d in -[NSObjectParameterBinder 
> _updateObject:observedController:observedKeyPath:context:] ()
> #5 0x7fff88540f08 in -[NSObject(NSKeyValueBindingCreation) 
> bind:toObject:withKeyPath:options:] ()
> 
> This application contains lots of programatic bindings similar to this one. 
> However this is the only one which throws an exception.
> 
> Should I be concerned about this?

Yes, The exception will leave your app in an invalid state.

> Is there anyway to debug this?

The breakpoint catches before the exception would be logged to console. Simply 
keep clicking the "continue" button in the debugger until it outputs the 
exception. Then read the Key-Value Coding guide on when setNilValueForKey: is 
called and how you can handle it. 

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: Binding Exception

2014-09-15 Thread Mike Abdullah

On 15 Sep 2014, at 21:42, Richard Charles  wrote:

> I have a binding that throws an Objective-C exception but the console 
> displays no output and the application does not crash but rather the 
> application runs fine. Enabling NSBindingDebugLogLevel 1 does not help, the 
> console still displays nothing. I am using Xcode 5.1.1 with the All 
> Exceptions breakpoint enabled.
> 
> [self bind:@"allowSelection"
>   toObject:_customView.window.windowController
>
> withKeyPath:@“widgetControllerManager.activeWidgetController.allowSelection"
>options:nil];
> 
> The stack trace looks like this.
> 
> #0 0x7fff909f0e4a in objc_exception_throw ()
> #1 0x7fff8a3f710c in +[NSException raise:format:] ()
> #2 0x7fff94b152a7 in -[NSObject(NSKeyValueCoding) setNilValueForKey:] ()
> #3 0x7fff94a4472e in -[NSObject(NSKeyValueCoding) setValue:forKey:] ()
> #4 0x7fff88549f0d in -[NSObjectParameterBinder 
> _updateObject:observedController:observedKeyPath:context:] ()
> #5 0x7fff88540f08 in -[NSObject(NSKeyValueBindingCreation) 
> bind:toObject:withKeyPath:options:] ()
> 
> This application contains lots of programatic bindings similar to this one. 
> However this is the only one which throws an exception.
> 
> Should I be concerned about this?
> 
> Is there anyway to debug this?

Read the docs for -setNilValueForKey:
Does that answer your question?


___

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: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Jerry Krinock

On 2014 Sep 15, at 12:47, Ken Thomases  wrote:

> Check the places where you can control how the outline view sizes the columns.

It seems that I only set column widths during -awakeFromNib.  Definitely not 
upon expanding an item.

> In particular, from the docs for -[NSOutlineViewDelegate 
> outlineView:sizeToFitWidthOfColumn:]:
> 
> "By default, NSOutlineView iterates every row in the table, accesses a cell 
> via preparedCellAtColumn:row:, and requests the cellSize to find the 
> appropriate largest width to use.
> 
> For accurate results and performance, it is recommended that this method is 
> implemented when using large tables. By default, large tables use a monte 
> carlo simulation instead of iterating every row.”

Those two paragraphs don’t make much sense to me, Ken.  For starters, when does 
NSOutlineView “iterate every row”?  I mean, this is a delegate method.  There 
is no default implementation.

Further up, it says that this method is "Invoked to allow the delegate to 
provide custom sizing behavior when a column’s resize divider is double 
clicked.”  I was never even aware of this “feature" :))  and had not 
implemented this method.  Just to test, I implemented it to return CGFloat 
value 50.0.  And, by golly, now when I double-click a column divider, in the 
table header, the preceding column resizes to 50 points.

I’m still thinking, but I can’t reckon any connection between this and 
-outlineView:child:ofItem: being sent proactively instead of lazily.  
Implementing it did not stop the “let’s get every row” craziness with 
-outlineView:child:ofItem:.
___

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: Binding Exception

2014-09-15 Thread Richard Charles
On Sep 15, 2014, at 2:52 PM, Keary Suska  wrote:

> Yes, The exception will leave your app in an invalid state.

Thank you, I was not aware of that.

> The breakpoint catches before the exception would be logged to console. 
> Simply keep clicking the "continue" button in the debugger until it outputs 
> the exception. Then read the Key-Value Coding guide on when 
> setNilValueForKey: is called and how you can handle it.

Clicking "continue" eventually causes the application to run freely but the 
debugger never produces any output. Weird. Implementing setNilValueForKey: 
fixed the issue.

On Sep 15, 2014, at 2:52 PM, Mike Abdullah  wrote:

> Read the docs for -setNilValueForKey:


I reviewed the documentation and yes implementing setNilValueForKey: fixed the 
issue.

Thanks for the help.
Richard Charles


___

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: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Ken Thomases
On Sep 15, 2014, at 3:54 PM, Jerry Krinock  wrote:

> On 2014 Sep 15, at 12:47, Ken Thomases  wrote:
> 
>> In particular, from the docs for -[NSOutlineViewDelegate 
>> outlineView:sizeToFitWidthOfColumn:]:
>> 
>> "By default, NSOutlineView iterates every row in the table, accesses a cell 
>> via preparedCellAtColumn:row:, and requests the cellSize to find the 
>> appropriate largest width to use.
>> 
>> For accurate results and performance, it is recommended that this method is 
>> implemented when using large tables. By default, large tables use a monte 
>> carlo simulation instead of iterating every row.”
> 
> Those two paragraphs don’t make much sense to me, Ken.  For starters, when 
> does NSOutlineView “iterate every row”?  I mean, this is a delegate method.  
> There is no default implementation.

NSOutlineView would iterate every row if the delegate does not implement this 
method and it needs to figure out how wide a column should be.

> Further up, it says that this method is "Invoked to allow the delegate to 
> provide custom sizing behavior when a column’s resize divider is double 
> clicked.”  I was never even aware of this “feature" :))  and had not 
> implemented this method.  Just to test, I implemented it to return CGFloat 
> value 50.0.  And, by golly, now when I double-click a column divider, in the 
> table header, the preceding column resizes to 50 points.
> 
> I’m still thinking, but I can’t reckon any connection between this and 
> -outlineView:child:ofItem: being sent proactively instead of lazily.  
> Implementing it did not stop the “let’s get every row” craziness with 
> -outlineView:child:ofItem:.

I had thought that the outline view wanted to know its ideal column width upon 
first showing, but apparently not.

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

Nib unloading and ARC

2014-09-15 Thread Jonathan Mitchell
I am using a NIB template, loading the same nib repetitively with a different 
owner each time (a non NSViewController subclass).
In the nib there is an NSValueBinding binding to the owner say: self.itemValue.
This all works fine.

However, nib owner items are not being dealloc’d.
This behaviour only occurs if the nib contains a binding to self.

Keary Suska has been down this route pre ARC : 
http://www.cocoabuilder.com/archive/cocoa/181029-proper-way-to-unload-loaded-nib-bindings.html

Nib top level objects seem to have an extra retain.
The docs recommend the following [topLevelObjs 
makeObjectsPerformSelector:@selector(release)];
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#//apple_ref/doc/uid/1051i-CH4-SW8

However I haven’t been able to get this explicit release approach to work under 
ARC.
Just calling CFRelease((__bridge CFTypeRef)(item)) on each of the top level 
objects doesn’t work.

Or should I refactor to make each NIB owner an NSViewController instance?

Thanks

Jonathan






___

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: Nib unloading and ARC

2014-09-15 Thread Ken Thomases
On Sep 15, 2014, at 5:00 PM, Jonathan Mitchell  wrote:

> I am using a NIB template, loading the same nib repetitively with a different 
> owner each time (a non NSViewController subclass).
> In the nib there is an NSValueBinding binding to the owner say: 
> self.itemValue.
> This all works fine.
> 
> However, nib owner items are not being dealloc’d.
> This behaviour only occurs if the nib contains a binding to self.

> Or should I refactor to make each NIB owner an NSViewController instance?

Yes.

From the release notes when NSViewController was originally introduced:
https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKitOlderNotes/#NSViewController

> A new class, NSViewController, has been added to the AppKit in Mac OS 10.5. 
> It serves roughly the same purpose as NSWindowController, but for  views 
> instead of windows. It:
> • Does the same sort of memory management of top-level objects that 
> NSWindowController does, taking the same care to prevent reference cycles 
> when controls are bound to the nib file's owner that NSWindowController began 
> taking in Mac OS 10.4.


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

Updating Content of NSFileWrapper

2014-09-15 Thread Charles Jenkins
My app’s document consists of a tree of individual word processing files to be 
saved as separate files within an NSFileWrapper.

Apple’s documentation suggests you can make the process of saving to a file 
wrapper more efficient if you only write out new or changed files. I’d like to 
do that and avoid needlessly rewriting subdocuments which haven’t changed.

The example Apple gives us in listing 6-5 of the Document-Based App Programming 
Guide demonstrates how to write data to a new file wrapper when the data 
doesn’t already exist (note that the calls to [fileWrappers objectForKey:] are 
expected to return nil). What the docs don’t demonstrate and I’m having 
difficulty figuring out is, how do you write changed data if that call doesn’t 
return nil?

Here’s the helper method I’m working on, including a comment showing where I 
don’t know what to do:

  func saveToWrapper(  
#parentWrapper: NSFileWrapper,
err: NSErrorPointer
)
  {
var fw = parentWrapper.fileWrappers[ filename ] as? NSFileWrapper
if ( contentWasModified || fw == nil ) {
  var attr = [ NSDocumentTypeDocumentAttribute : NSRTFTextDocumentType ]
  var range = NSRange( location: 0, length: content.length )
  var data = content.dataFromRange(
range,
documentAttributes: attr,
error: err
  )
  if ( fw == nil ) {
parentWrapper.addRegularFileWithContents( data, preferredFilename: 
filename )
  } else {
// What the heck do I do here? How to I update fw's contents?
  }
}
 }


This is an instance method of a class which represents the subdocument. The 
class contains the instance variables filename: String, content: 
NSAttributedString, and contentWasModified: Bool.

—

Charles Jenkins

___

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: Updating Content of NSFileWrapper

2014-09-15 Thread Quincey Morris
On Sep 15, 2014, at 19:12 , Charles Jenkins  wrote:

>// What the heck do I do here? How to I update fw's contents?

You do the “obvious” thing — remove the existing file wrapper and create a new 
one.

The clearest logic for this would be:

If this file’s content is modified, remove any existing file wrapper.
Then, if there’s no file wrapper, create the file data and create the 
file wrapper.

So there’s no real difference between the create and the update case. 



___

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: Want NSTableView NSOutlineView to load lazy like iOS?

2014-09-15 Thread Jerry Krinock
Well, I made a little demo project containing an NSOutlineView, cell-based with 
two text cell/columns, connected data source to app delegate, and in there 
implemented data source methods to supply 1000 items to the root.

Result: Behaves lazily as desired.  Initially, it asks for about 100 more items 
than are visible, and whenever scrolling causes the headroom to get below 100 
items, it asks for a bunch more; if you scroll very slowly, about one window’s 
worth.

So I need to dig in and find what is different in my real project that makes 
NSOutlineView so proactive :(

Jerry


___

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