Re: NSMenu in NSTableView column

2014-08-13 Thread Jonathan Taylor
 I would create a class, say, SignalChannel, with name (for description, but 
 we may not ant to use description for obvious reasons...) and channelID 
 properties. I would then populate the NSPopupButtonCell with SignalChannel 
 objects. This will abstract the model from the view, which is better form 
 anyway.

Ah, I've worked out the underlying problem I've been having. I had been trying 
things along these lines and completely failing to get the popup menu to 
populate correctly. It was working for a standalone popup but not within the 
table, and I was assuming I was doing something wrong and/or it was more 
complex than I realised, and had basically decided not to continue stumbling 
around trying to make it work. Then I found this:
http://stackoverflow.com/questions/14708947/nspopupbutton-in-view-based-nstableview-getting-bindings-to-work
which describes what seems to be a bug in the implementation, along with the 
workaround (binding to an outlet property on the file's owner, rather than 
directly to the array controller). Weird.
___

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

Translating to Swift

2014-08-13 Thread Gerriet M. Denkmann

How could I translate this to Swift?

+ (Thing *)sharedThing
{
static Thing *commonThing;
static dispatch_once_t justOnce;
dispatch_once( justOnce, ^void
{
commonThing = [ [ Thing alloc ] init ];
}
);

return commonThing;
}

Gerriet.

___

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: Translating to Swift

2014-08-13 Thread Jean-Daniel Dupas

At global scope

var sharedThing : Thing = Thing();

Le 13 août 2014 à 12:30, Gerriet M. Denkmann gerr...@mdenkmann.de a écrit :

 
 How could I translate this to Swift?
 
 + (Thing *)sharedThing
 {
   static Thing *commonThing;
   static dispatch_once_t justOnce;
   dispatch_once( justOnce, ^void
   {
   commonThing = [ [ Thing alloc ] init ];
   }
   );
   
   return commonThing;
 }
 
 Gerriet.
 
 ___
 
 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/mailing%40xenonium.com
 
 This email sent to mail...@xenonium.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

diff tool on iOS?

2014-08-13 Thread Koen van der Drift
Is there any way to use a diff tool in an iOS app? My app at one point
needs to find the difference between two large text files, and using diff
or something similar may be a possible solution. Both files are downloaded
as NSData objects from an external source, and right now I have converted
them to NSString objects. But they can be in any format, as long as I can
find a way which lines have changed.

Thanks,

- Koen.
___

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: diff tool on iOS?

2014-08-13 Thread ChanMaxthon
I think you can embed code from BSD diff in your program. That is plain C and 
you just need to call it using your Objective-C code.

Alternatively you can look into the implementation of BSD diff or GNU diffutils 
and rewrite it using Objective-C or Swift for your project.

Sent from my iPad

 On Aug 13, 2014, at 20:34, Koen van der Drift koenvanderdr...@gmail.com 
 wrote:
 
 Is there any way to use a diff tool in an iOS app? My app at one point
 needs to find the difference between two large text files, and using diff
 or something similar may be a possible solution. Both files are downloaded
 as NSData objects from an external source, and right now I have converted
 them to NSString objects. But they can be in any format, as long as I can
 find a way which lines have changed.
 
 Thanks,
 
 - Koen.
 ___
 
 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/xcvista%40me.com
 
 This email sent to xcvi...@me.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: diff tool on iOS?

2014-08-13 Thread Koen van der Drift
I thought about diff, but can I use that without NSTask, etc which aren't
available on iOS?

Also came across this:
https://github.com/inquisitiveSoft/DiffMatchPatch-ObjC, which could be
useful.

Thanks for your imput,

- Koen.




On Wed, Aug 13, 2014 at 9:03 AM, ChanMaxthon xcvi...@me.com wrote:

 I think you can embed code from BSD diff in your program. That is plain C
 and you just need to call it using your Objective-C code.

 Alternatively you can look into the implementation of BSD diff or GNU
 diffutils and rewrite it using Objective-C or Swift for your project.

 Sent from my iPad

  On Aug 13, 2014, at 20:34, Koen van der Drift koenvanderdr...@gmail.com
 wrote:
 
  Is there any way to use a diff tool in an iOS app? My app at one point
  needs to find the difference between two large text files, and using diff
  or something similar may be a possible solution. Both files are
 downloaded
  as NSData objects from an external source, and right now I have converted
  them to NSString objects. But they can be in any format, as long as I can
  find a way which lines have changed.
 
  Thanks,
 
  - Koen.
  ___
 
  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/xcvista%40me.com
 
  This email sent to xcvi...@me.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: diff tool on iOS?

2014-08-13 Thread Sergio Campamá
I think he meant to replicate the diff functionality inside your app,
and handle the output your own way to display the results. AFAIK, you
can't call any command line programs from an iOS app...
--
Sergio Campamá
sergiocamp...@gmail.com



On Wed, Aug 13, 2014 at 7:31 AM, Koen van der Drift
koenvanderdr...@gmail.com wrote:
 I thought about diff, but can I use that without NSTask, etc which aren't
 available on iOS?

 Also came across this:
 https://github.com/inquisitiveSoft/DiffMatchPatch-ObjC, which could be
 useful.

 Thanks for your imput,

 - Koen.




 On Wed, Aug 13, 2014 at 9:03 AM, ChanMaxthon xcvi...@me.com wrote:

 I think you can embed code from BSD diff in your program. That is plain C
 and you just need to call it using your Objective-C code.

 Alternatively you can look into the implementation of BSD diff or GNU
 diffutils and rewrite it using Objective-C or Swift for your project.

 Sent from my iPad

  On Aug 13, 2014, at 20:34, Koen van der Drift koenvanderdr...@gmail.com
 wrote:
 
  Is there any way to use a diff tool in an iOS app? My app at one point
  needs to find the difference between two large text files, and using diff
  or something similar may be a possible solution. Both files are
 downloaded
  as NSData objects from an external source, and right now I have converted
  them to NSString objects. But they can be in any format, as long as I can
  find a way which lines have changed.
 
  Thanks,
 
  - Koen.
  ___
 
  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/xcvista%40me.com
 
  This email sent to xcvi...@me.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/sergiocampama%40gmail.com

 This email sent to sergiocamp...@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: NSMenu in NSTableView column

2014-08-13 Thread Keary Suska

On Aug 13, 2014, at 4:04 AM, Jonathan Taylor jonathan.tay...@glasgow.ac.uk 
wrote:

 I would create a class, say, SignalChannel, with name (for description, 
 but we may not ant to use description for obvious reasons...) and 
 channelID properties. I would then populate the NSPopupButtonCell with 
 SignalChannel objects. This will abstract the model from the view, which is 
 better form anyway.
 
 Ah, I've worked out the underlying problem I've been having. I had been 
 trying things along these lines and completely failing to get the popup menu 
 to populate correctly. It was working for a standalone popup but not within 
 the table, and I was assuming I was doing something wrong and/or it was more 
 complex than I realised, and had basically decided not to continue stumbling 
 around trying to make it work. Then I found this:
 http://stackoverflow.com/questions/14708947/nspopupbutton-in-view-based-nstableview-getting-bindings-to-work
 which describes what seems to be a bug in the implementation, along with the 
 workaround (binding to an outlet property on the file's owner, rather than 
 directly to the array controller). Weird.

That link refers to a view-based table view, which is a different animal 
altogether. Is your table view cell or view based? It makes a big difference...

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: diff tool on iOS?

2014-08-13 Thread Koen van der Drift
Thanks the clarification, I misread the answer.

Any tips for where I can find the source code for BSD diff? I found the GNU
diffutils already here: http://www.gnu.org/software/diffutils/.

- Koen.




On Wed, Aug 13, 2014 at 10:41 AM, Sergio Campamá sergiocamp...@gmail.com
wrote:

 I think he meant to replicate the diff functionality inside your app,
 and handle the output your own way to display the results. AFAIK, you
 can't call any command line programs from an iOS app...
 --
 Sergio Campamá
 sergiocamp...@gmail.com



 On Wed, Aug 13, 2014 at 7:31 AM, Koen van der Drift
 koenvanderdr...@gmail.com wrote:
  I thought about diff, but can I use that without NSTask, etc which aren't
  available on iOS?
 
  Also came across this:
  https://github.com/inquisitiveSoft/DiffMatchPatch-ObjC, which could be
  useful.
 
  Thanks for your imput,
 
  - Koen.
 
 
 
 
  On Wed, Aug 13, 2014 at 9:03 AM, ChanMaxthon xcvi...@me.com wrote:
 
  I think you can embed code from BSD diff in your program. That is plain
 C
  and you just need to call it using your Objective-C code.
 
  Alternatively you can look into the implementation of BSD diff or GNU
  diffutils and rewrite it using Objective-C or Swift for your project.
 
  Sent from my iPad
 
   On Aug 13, 2014, at 20:34, Koen van der Drift 
 koenvanderdr...@gmail.com
  wrote:
  
   Is there any way to use a diff tool in an iOS app? My app at one point
   needs to find the difference between two large text files, and using
 diff
   or something similar may be a possible solution. Both files are
  downloaded
   as NSData objects from an external source, and right now I have
 converted
   them to NSString objects. But they can be in any format, as long as I
 can
   find a way which lines have changed.
  
   Thanks,
  
   - Koen.
   ___
  
   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/xcvista%40me.com
  
   This email sent to xcvi...@me.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/sergiocampama%40gmail.com
 
  This email sent to sergiocamp...@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: NSMenu in NSTableView column

2014-08-13 Thread Jonathan Taylor
 Ah, I've worked out the underlying problem I've been having. I had been 
 trying things along these lines and completely failing to get the popup menu 
 to populate correctly. It was working for a standalone popup but not within 
 the table, and I was assuming I was doing something wrong and/or it was more 
 complex than I realised, and had basically decided not to continue stumbling 
 around trying to make it work. Then I found this:
 http://stackoverflow.com/questions/14708947/nspopupbutton-in-view-based-nstableview-getting-bindings-to-work
 which describes what seems to be a bug in the implementation, along with the 
 workaround (binding to an outlet property on the file's owner, rather than 
 directly to the array controller). Weird.
 
 That link refers to a view-based table view, which is a different animal 
 altogether. Is your table view cell or view based? It makes a big 
 difference...

As it stands right now, it's view based (I switched it in InterfaceBuilder). 
Things seem to be working fine with that workaround. 

I started writing a long email to the list on the question of view- vs 
cell-based tables, but as is often the case, in the course of writing it I 
worked out the answer to my particular question at the time. I ended up with 
view based because Apple give clear instructions for how to bind things for 
them in Table View Programming Guide for Mac. Their advice for cell-based 
tables is rather unhelpful, just saying that it's very different and you 
should configure the column’s cell’s bindings. Well thanks Apple! Their 
instructions for view-based tables were clear, so I went with that.
___

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: diff tool on iOS?

2014-08-13 Thread Marco S Hyman
On Aug 13, 2014, at 7:54 AM, Koen van der Drift koenvanderdr...@gmail.com 
wrote:

 Any tips for where I can find the source code for BSD diff? I found the GNU
 diffutils already here: http://www.gnu.org/software/diffutils/.

Try one of the bsd source repositories.  An example that I'm
familiar with is the OpenBSD tree.  Diff source is at

http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/usr.bin/diff/

Marc
___

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: Advise on referencing NSDocument from custom view

2014-08-13 Thread Luc Van Bogaert

I've reworked my model, view and controller classes in the way you've indicated 
below. Thanks.

I do have another question about this kind of setup. In the process I decided 
that it would be a good idea to have a designated initializer for my custom 
view that sets a reference to the model object using a weak property like this: 
'initWithModel: (MyModel *) model'.
This seems to work fine, and I now have a reference to my model object from 
MyDocument, MyWindowController and also from MyView.

Next I wanted to have MyView observe some model properties, so I set the view 
object as an observer from within the 'initWithModel:' initializer, like this : 
'self.model addObserver: self keyName: @property 

My question now is , where I should remove MyView as an observer with 
'self.model removeObserver: self forKey: @property...' '?
I tried to do this in 'dealloc', but it seems that from time to time my model 
object is pulled right from under my when I close the document window, 
resulting in an error stating that MyModel was deallocated while it still had 
observers attached to it. Strangely, this doen't every time though, but just 
from time to time.

For now, I add and remove the custom view as an observer from 
MyWindowController, which seems to work fine, but I'm still not sure why I 
can't do this in the MyView object itself.

-- 
Luc Van Bogaert

On 10 Aug 2014, at 23:05, Quincey Morris quinceymor...@rivergatesoftware.com 
wrote:

 On Aug 10, 2014, at 13:16 , Luc Van Bogaert luc.van.boga...@me.com wrote:
 
 Let's see if I understand this correctly: do you mean I could create a 
 separate model class, eg. Drawing with all of it's properties and 
 reference this in my document class as an instance variable or even as a 
 property.
 Then, from my custom view, instead of using [[self.window.windowController 
 document] someProperty]', I could use '[self.window.windowController 
 someProperty]', which in turn would message my model object to return the 
 value of 'someProperty' using 'return [self.document someProperty]' ? 
 
 To be specific:
 
 In a document-based app, I will generally have MyDocument, MyWinController 
 and MyModel.
 
 MyDocument has a MyModel property, referencing the model that it loaded from 
 the document file (or whatever).
 
 MyWinController has a MyModel property, referencing the same model as the 
 document.
 
 A custom MyView would also have a MyModel property referencing the same 
 model, initialized in any of various ways depending on how the view was 
 created. The view would then use myModel.someProperty whenever it needed it, 
 perhaps even binding to it.
 
 Putting a derived “someProperty” directly on the window controller, or even 
 on a view controller, *is* feasible too. Often, I find, I use this approach 
 when the view presents a somewhat transformed picture of the data model. 
 Databasey kinds of apps (such as master/detail) often seem to want to use the 
 real data model directly. UIey kinds of apps often seem to want to use a 
 transformed model.
 



smime.p7s
Description: S/MIME cryptographic signature
___

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

Backup eligibility (iCloud/iTunes) for iOS shared app group container

2014-08-13 Thread Ben Kennedy
Hello all,

What is the persistence and backup policy for files stored in an app group 
shared container on iOS 8 -- that is, the directory returned by -[NSFileManager 
containerURLForSecurityApplicationGroupIdentifier:] ?

More specifically, can I treat this directory in a similar manner as the app's 
regular Documents directory such as returned by [[NSFileManager defaultManager] 
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] ? (In 
particular, the latter is preserved in user backups via iTunes or iCloud.)

The “iOS Data Storage Guidelines” 
https://developer.apple.com/icloud/documentation/data-storage/index.html do 
not address this, nor do its linked references.

We're developing an Action Extension and my desire is to maintain some 
persistent shared data between the extension and the containing app, and 
migrating from the Documents directory to the shared container seems like the 
reasonably obvious thing to do.

thanks,

-ben



___

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: Advise on referencing NSDocument from custom view

2014-08-13 Thread Quincey Morris
On Aug 13, 2014, at 11:31 , Luc Van Bogaert luc.van.boga...@me.com wrote:

 My question now is , where I should remove MyView as an observer with 
 'self.model removeObserver: self forKey: @property...' '?
 I tried to do this in 'dealloc', but it seems that from time to time my model 
 object is pulled right from under my when I close the document window, 
 resulting in an error stating that MyModel was deallocated while it still had 
 observers attached to it.

Yes, this behavior is a consequence of the fact that the view’s “model” 
property is weak, and therefore not KVO compliant. (It can change to nil 
without anyone getting notified.)

One way to handle this is to implement the window delegate method 
‘windowWillClose:’ in your window controller, and use that to inform the view 
that it should stop observing the model.

Unfortunately, there’s one other case you probably need to handle — what 
happens when the model is deallocated for some other reason. It’s possible that 
this isn’t possible in your app, but consider what happens if the user reverts 
the document, and the document object handles that by re-reading the document 
file and creating a new model. (I *think* that’s what happens if you don’t have 
any revert-handling code of your own.)

In that case , the view’s weak “model” property will change to nil, which isn’t 
very useful.

The upshot of this is that you’ll likely have a model-monitoring slab of code 
in your window controller, which is responsible for keeping the view up to 
date. Then, you’d probably use this mechanism to get the model reference to the 
view initially, rather than having the custom initializer. Or, you’d change the 
view to observe a “model” property of the window controller, which itself is 
derived from the document’s “model” property.

But the details will vary depending on the details of your app.

___

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

KVO query

2014-08-13 Thread Jonathan Mitchell
I have a key path like so which is observed:

submission.status.name

At one point i need to invoke a manual KVO notification like so:

[submission willChangeValueForKey:@“status”];
[submission didChangeValueForKey:@“status”];

This raises like so:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Cannot update for observer NSKeyValueObservance 0x608000ac21b0 for 
the key path status.name from Submission 0x6080003aa800, most likely 
because the value for the key status has changed without an appropriate KVO 
notification being sent. Check the KVO-compliance of the Submission class.’

I am using manual KVO because my submission object is a wrapper around a Mono 
managed class.
I receive a callback that the managed status object has changed and want to 
propagate that via KVO.
The true situation is generic : i receive a callback that a managed property P 
has changed and want to raise manual KVO notifications in a compliant manner.

Is there a way for me to programatically determine what sequence of manual  KVO 
notifications  I will require to maintain KVO compliance?
I imagine that the framework code uses - observationInfo to achieve this but 
that is opaque to client code.
I am trying to avoid having lots of explicit 
+keyPathsForValuesAffectingValueForKey: methods.

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: KVO query

2014-08-13 Thread Lee Ann Rucker
Have you implemented +automaticallyNotifiesObserversForKey: and returned NO for 
“status” ?

On Aug 13, 2014, at 2:53 PM, Jonathan Mitchell jonat...@mugginsoft.com wrote:

 I have a key path like so which is observed:
 
 submission.status.name
 
 At one point i need to invoke a manual KVO notification like so:
 
 [submission willChangeValueForKey:@“status”];
 [submission didChangeValueForKey:@“status”];
 
 This raises like so:
 
 Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
 reason: 'Cannot update for observer NSKeyValueObservance 0x608000ac21b0 for 
 the key path status.name from Submission 0x6080003aa800, most likely 
 because the value for the key status has changed without an appropriate KVO 
 notification being sent. Check the KVO-compliance of the Submission class.’
 
 I am using manual KVO because my submission object is a wrapper around a Mono 
 managed class.
 I receive a callback that the managed status object has changed and want to 
 propagate that via KVO.
 The true situation is generic : i receive a callback that a managed property 
 P has changed and want to raise manual KVO notifications in a compliant 
 manner.
 
 Is there a way for me to programatically determine what sequence of manual  
 KVO notifications  I will require to maintain KVO compliance?
 I imagine that the framework code uses - observationInfo to achieve this but 
 that is opaque to client code.
 I am trying to avoid having lots of explicit 
 +keyPathsForValuesAffectingValueForKey: methods.
 
 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: KVO query

2014-08-13 Thread Ken Thomases

On Aug 13, 2014, at 4:53 PM, Jonathan Mitchell jonat...@mugginsoft.com wrote:

 I have a key path like so which is observed:
 
 submission.status.name
 
 At one point i need to invoke a manual KVO notification like so:
 
 [submission willChangeValueForKey:@“status”];
 [submission didChangeValueForKey:@“status”];
 
 This raises like so:
 
 Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
 reason: 'Cannot update for observer NSKeyValueObservance 0x608000ac21b0 for 
 the key path status.name from Submission 0x6080003aa800, most likely 
 because the value for the key status has changed without an appropriate KVO 
 notification being sent. Check the KVO-compliance of the Submission class.’
 
 I am using manual KVO because my submission object is a wrapper around a Mono 
 managed class.
 I receive a callback that the managed status object has changed and want to 
 propagate that via KVO.
 The true situation is generic : i receive a callback that a managed property 
 P has changed and want to raise manual KVO notifications in a compliant 
 manner.
 
 Is there a way for me to programatically determine what sequence of manual  
 KVO notifications  I will require to maintain KVO compliance?

You have to issue the -willChange… _before_ the property has changed.  That's 
because that's KVO's only opportunity to get the value that's about to become 
old and remove its observations for the properties of that old object.

So, that pattern of issuing -willChange… followed immediately by -didChange… 
with nothing actually changing in between is a sure sign of a problem.

The solution is annoying but relatively simple.  You need to hold a strong 
reference to the old object in a property of your own.  So, you need a property 
status that is _not_ just a pass-through to some other API.  It needs to be 
backed by an instance variable (e.g. _status) that is a strong reference to the 
object.  Then, when you receive the notification from the underlying API that 
something has changed, you fetch the new object from that API and assign it to 
self.status.  That assignment is KVO-compliant.  You can/should then eliminate 
your manual -will/didChange… invocations.

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: KVO query

2014-08-13 Thread Quincey Morris
On Aug 13, 2014, at 14:53 , Jonathan Mitchell jonat...@mugginsoft.com wrote:

 At one point i need to invoke a manual KVO notification like so:
 
 [submission willChangeValueForKey:@“status”];
 [submission didChangeValueForKey:@“status”];
 
 This raises like so:
 
 Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
 reason: 'Cannot update for observer NSKeyValueObservance 0x608000ac21b0 for 
 the key path status.name from Submission 0x6080003aa800, most likely 
 because the value for the key status has changed without an appropriate KVO 
 notification being sent. Check the KVO-compliance of the Submission class.’

This is one of those infuriating errors that is hard to make sense of. Try 
thinking about it literally.

Because you’re observing the “status.name” path from ‘submission’, the observer 
is *also* observing the “name” path from ‘submission.status’**. In your 
scenario, the originally observed ‘status’ instance (call it X) is no longer 
the current ‘status’ instance at willChange time (it’s now Y, say), and in 
general it might not be the same as that at didChange time (Z, say). Even if Y 
== Z, there’s been a non-KVO-compliant change in ‘status’ prior to the 
notification being sent.

Now, we do this quite often, without problems, but I’d suggest that’s only in 
cases where the “temporarily non KVO compliant” change is for the *last* key of 
the path — in which case the last object isn’t being observed, just because 
it’s the last key.

So, in the case of a non-KVO-compliant change to the value of a non-terminal 
key path object, the non-KVO-compliance may not be tolerated by the frameworks. 
Hence this error message.

What I suggest you try is to make two properties: “currentStatus” and 
“observableStatus”. The second of these would be updated KVO compliantly (i.e. 
via its setter) when you know that the first has changed and the change should 
be propagated (i.e. in the places where you now trigger the 
willChange/didChange notification manually). Code in the ‘submission’ class can 
use ‘self.currentStatus’ to get or set the most recent status object; observers 
would observe “observableStatus”, of course.



** Because there’re “really” no such thing as a key path observation. It’s 
“really” a chain of object/key observations.

___

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

autolayout-based animation on NSView

2014-08-13 Thread Roland King
I have a constraint-based NSView layout which I can flip between states by 
adjusting the constraint priorities and/or constants, and/or removing and 
replacing some constraints. At the same time I make some views invisible or 
visible again. All that stuff say is in a method on the view .. 

-(void)updateConstraintsAndVariousViewPropertiesForState:(BOOL)state;

With the fairly straightforward UIView on iOS I’m used to doing this

[ myUIView layoutIfNeeded ]
[ myUIView animateWithDuration:duration animations:^{
[ myUIView 
updateConstraintsAndVariousViewPropertiesForState:state ];
[ myUIView layoutIfNeeded ];
} ];

The view properties change, the second layoutIfNeeded re-evaluates the 
constraints and fixed up all the frames and bounds etc and the whole thing 
animates smoothly to the new state. 

How do I do this with an *NSView*? 

Doing some docs diving I found animator proxies, get the proxy, call the method 
on the proxy and it should animate. So I tried

[ myNSView layoutSubtreeIfNeeded ];
[ myNSView updateConstraintsAndVariousViewPropertiesForState:state ];
[ [ myNSView animator ] layoutSubtreeIfNeeded ];

no animation, layout change, but no animation, just jumps. I put it in an 
NSAnimationContext beginGrouping/endGrouping box … that didn’t help. Changing 
some alpha properties in the same block did animate, but it seems the 
layoutSubtreeIfNeeded doesn’t work with animator proxies. I tried just setting 
constraint priorities using their animator proxies, that didn’t work either, 
still just jumped. Looks like the only animator proxy able thing on a 
constraint is the constant. So it looks like animator proxies aren’t going to 
fly. 

Where do I go next? I see a few comments about layer-backed views, but examples 
are few, do I need to back myself with a layer for this? 



___

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: autolayout-based animation on NSView

2014-08-13 Thread Ken Thomases
On Aug 13, 2014, at 8:22 PM, Roland King r...@rols.org wrote:

 I have a constraint-based NSView layout which I can flip between states by 
 adjusting the constraint priorities and/or constants, and/or removing and 
 replacing some constraints. At the same time I make some views invisible or 
 visible again. All that stuff say is in a method on the view .. 
 
   -(void)updateConstraintsAndVariousViewPropertiesForState:(BOOL)state;
 
 With the fairly straightforward UIView on iOS I’m used to doing this
 
   [ myUIView layoutIfNeeded ]
   [ myUIView animateWithDuration:duration animations:^{
   [ myUIView 
 updateConstraintsAndVariousViewPropertiesForState:state ];
   [ myUIView layoutIfNeeded ];
   } ];
 
 The view properties change, the second layoutIfNeeded re-evaluates the 
 constraints and fixed up all the frames and bounds etc and the whole thing 
 animates smoothly to the new state. 
 
 How do I do this with an *NSView*? 
 
 Doing some docs diving I found animator proxies, get the proxy, call the 
 method on the proxy and it should animate. So I tried
 
   [ myNSView layoutSubtreeIfNeeded ];
   [ myNSView updateConstraintsAndVariousViewPropertiesForState:state ];
   [ [ myNSView animator ] layoutSubtreeIfNeeded ];
 
 no animation, layout change, but no animation, just jumps. I put it in an 
 NSAnimationContext beginGrouping/endGrouping box … that didn’t help. Changing 
 some alpha properties in the same block did animate, but it seems the 
 layoutSubtreeIfNeeded doesn’t work with animator proxies. I tried just 
 setting constraint priorities using their animator proxies, that didn’t work 
 either, still just jumped. Looks like the only animator proxy able thing on a 
 constraint is the constant. So it looks like animator proxies aren’t going to 
 fly. 
 
 Where do I go next? I see a few comments about layer-backed views, but 
 examples are few, do I need to back myself with a layer for this? 

As you discovered, you can set a constraint constant on the constraint's 
animator to animate that change in the constraint.  That doesn't work for 
priorities and really couldn't.  There's no in-between state with priorities.  
To the extent they matter at all, it's because it switches which constraints 
are in effect, and that's a binary condition.  When you set the constant on the 
animator, you're really animating the constraint, not the view positions.  The 
system adjusts the constraint a little bit, lays out the views according to the 
constraints, draws, adjusts the constraint some more, etc.

The alternative is to animate the view positions by doing something similar as 
in UIKit.  You make sure the frames are up-to-date with respect to the layout 
and then, in an animation group, you change the constraints and lay them out 
again.  The resulting view frame changes get animated.

It should work to do:

[view layoutSubtreeIfNeeded];
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
context.duration = 0.25; // you can leave this out if the default is 
acceptable
context.allowsImplicitAnimation = YES;
[view updateConstraintsAndVariousViewPropertiesForState:state];
[view layoutSubtreeIfNeeded];
} completionHandler:nil];

This does require layer-backed views.  It may be that you can leave out setting 
allowsImplicitAnimation if you use the view's animator for the second 
-layoutSubtreeIfNeeded, but I'm not sure.  Supposedly, the animator turns on 
implicit animation, but I don't know if that's only when setting animatable 
properties.

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: autolayout-based animation on NSView

2014-08-13 Thread Roland King
 
 It should work to do:
 
 [view layoutSubtreeIfNeeded];
 [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
context.duration = 0.25; // you can leave this out if the default is 
 acceptable
context.allowsImplicitAnimation = YES;
[view updateConstraintsAndVariousViewPropertiesForState:state];
[view layoutSubtreeIfNeeded];
 } completionHandler:nil];
 
 This does require layer-backed views.  It may be that you can leave out 
 setting allowsImplicitAnimation if you use the view's animator for the second 
 -layoutSubtreeIfNeeded, but I'm not sure.  Supposedly, the animator turns on 
 implicit animation, but I don't know if that's only when setting animatable 
 properties.


Thanks - that works perfectly, even animates the ‘hidden’ property smoothly 
which I wasn’t getting with the animator proxy. I’ve yanked out most of the 
proxies from the update method, don’t need them and it makes the code scruffy. 

Now I know what I am looking for (NSAnimationContext runAnimationGroup..) I did 
find an example in the docs, however it’s wrong and uses ‘[ NSView 
layoutIfNeeded ]’ for the OSX example instead of layoutSubtreeIfNeeded .. you 
can guess which method I was googling on :(

I’ll add ‘turn on layer-backed views’ to my OSX checklist, it seems like they 
may act more like the world I’m used to. Pleased I learned UIKit first or I 
wouldn’t even know what questions to ask, although even UIKit is slowly 
crufting up. 

One animation to go and it’s shipping time ! 
___

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