I've got an OS X app syncing a single document through a ubiquity container back and forth to an iOS equivalent app. The iOS app receives data whenever it changes on the Mac side and sends it whenever it changes on the iOS side (so the iOS app is working all around), and the Mac app sends the data whenever it is changed on the Mac side and it receives the data when the app is launched, but it doesn't seem to be checking again for any data while it runs. I'd like it to update with any changes automatically and immediately, like the OS X "Notes" app does from changes on the iOS side.

At launch, this is the relevant function that gets called:

```
+(NSMutableDictionary *)getAllNotes {
    if(allNotes == nil) {
        allNotes = [[NSMutableDictionary alloc]initWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey:kAllNotes]];

        cloudDoc = [[CloudDocument alloc]initWithContentsOfURL:[self notesURL] ofType:NSPlainTextDocumentType error:nil];
        [cloudDoc saveToURL:[self notesURL] ofType:NSPlainTextDocumentType forSaveOperation:NSSaveOperation error:nil];
    }
    return allNotes;
}

```

and that "CloudDocument" class (which is a subclass of `NSDocument`) includes:

```
#import "Data.h"

@implementation CloudDocument

-(NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
    return [NSKeyedArchiver archivedDataWithRootObject:[Data getAllNotes]];
}

-(BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
    NSDictionary *dict = (NSDictionary *)[NSKeyedUnarchiver unarchiveObjectWithData:(NSData *)data];
    [Data didReceiveCloudData:dict];
    return YES;
}

+(BOOL)autosavesInPlace {
    return YES;
}

@end

```

which kicks it back to:

```
+(void)didReceiveCloudData:(NSDictionary *)d {
    allNotes = [[NSMutableDictionary alloc]initWithDictionary:d];
    [[NSUserDefaults standardUserDefaults] setObject:allNotes forKey:kAllNotes];

    [cloudDoc updateChangeCount:NSChangeDone];
}

```

I think the problem is just that I don't have any part of my code that is equivalent to the phrase "check periodically to see if the ubiquity container has changed, and then do..." etc. I'm sure there's a well-known process for this (some notification event in `NSDocument` or something), but I've searched around and everything I find is either for iOS/UIDocuments instead of OS X/NSDocuments, or it's all theory and over my head without any tangible code samples to comb through and pick apart. 

Can anyone help me out with a method for registering that an iCloud document in the ubiquity container has changed, and ideally where to put it (AppDelegate, CloudDocument.m, etc)? I only have one file syncing around, signified by the constant `kAllNotes`, so I don't need to track a bunch of different files or anything. I'm pretty sure I can use the code that runs at launch to do what needs to be done, I just can't figure out what to do to start the auto-syncing process.

Thank you in advance!

PS I'm still a beginner, so tutorials and code samples are much appreciated.