This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.xm
More file actions
31 lines (28 loc) · 1.3 KB
/
example.xm
File metadata and controls
31 lines (28 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#import <Notes/Notes.h>
-(void)savenote {
NoteContext *noteContext = [[%c(NoteContext) alloc] init];
NSManagedObjectContext *context = [noteContext managedObjectContext];
NoteStoreObject *store = [noteContext defaultStoreForNewNote];
NoteObject *note = [%c(NSEntityDescription) insertNewObjectForEntityForName:@"Note" inManagedObjectContext:context];
NoteBodyObject *body = [%c(NSEntityDescription) insertNewObjectForEntityForName:@"NoteBody" inManagedObjectContext:context];
NSString *notetext = @"Your custom note text";
NSArray *sep = [notetext componentsSeparatedByString:@"\n"];
notetext = [sep componentsJoinedByString:@"<br />"];
body.content = notetext;
body.owner = note;
note.store = store;
note.integerId = [noteContext nextIndex];
note.title = @"Title of Note";
note.summary = @"summary here";
note.body = body;
note.creationDate = [NSDate date];
note.modificationDate = [NSDate date];
NSError *error;
BOOL success = [noteContext saveOutsideApp:&error];
if (!success) {
UIAlertView*theAlert = [[UIAlertView alloc] initWithTitle:@"Error!" message:[error localizedDescription] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[theAlert show];
[theAlert release];
}
[noteContext release];
}