• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDocument and KVO compliance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDocument and KVO compliance


  • Subject: Re: NSDocument and KVO compliance
  • From: "email@hidden" <email@hidden>
  • Date: Sat, 19 Oct 2013 11:38:34 +0100

On 19 Oct 2013, at 03:58, Jerry Krinock <email@hidden> wrote:

>
> In Core Data documents, I ignore -[NSDocument isDocumentEdited] and instead use
> -[NSManagedObjectContext hasChanges].
>
> "In OS X v10.6 and later, this property is key-value observing compliant."
>

Unfortunately I am not using CoreData but the .NET Entity Framework.
I use Dubrovnik (https://github.com/ThesaurusSoftware/Dubrovnik) to generate a set of ObjC -> .NET (Mono) bindings and then using Cocoa bindings to the generated Obj-C.
One upshot of this that I don't have a KVO compliant - hasChanges property.

The project uses bindings so my solution is track the change activity via the binding activity.
All view bindings are made via a NSViewController subclass's -representedObject.
Any control bound to a key path invoking self calls the setValue:forKeyPath: override and marks the document as changed.

I don't know if this is a common technique but I use it regularly to track binding changes.

- (void)setValue:(id)value forKeyPath:(NSString *)keyPath
{
    // all bindings that reference self (such as self.representedObject.xxx)
    // will pass through this method
    if ([keyPath rangeOfString:@"self.representedObject."].location != NSNotFound) {
        [self.document updateChangeCount:NSChangeDone];
    }
    [super setValue:value forKeyPath:keyPath];
}

J


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSDocument and KVO compliance
      • From: Jerry Krinock <email@hidden>
References: 
 >NSDocument and KVO compliance (From: "email@hidden" <email@hidden>)
 >Re: NSDocument and KVO compliance (From: Seth Willits <email@hidden>)
 >Re: NSDocument and KVO compliance (From: Kevin Perry <email@hidden>)
 >Re: NSDocument and KVO compliance (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Converting views to use layer backing
  • Next by Date: Setting key equivalent for menus depending on window
  • Previous by thread: Re: NSDocument and KVO compliance
  • Next by thread: Re: NSDocument and KVO compliance
  • Index(es):
    • Date
    • Thread