NSArrayController(Chapter 8 of Cocoa Programming for Mac OS X)
Person1 #import "Person.h"
2
3
4 @implementation Person
5
6 - (id)init
7 {
8 ;
9 expectedRaise = 5.0;
10 personName = @"New Person";
11 return self;
12 }
13
14 - (void)dealloc
15 {
16 ;
17 ;
18 }
19
20 - (void)setNilValueForKey:(NSString *)key
21 {
22 if()
23 {
24 ;
25 }
26 else
27 {
28 ;
29 }
30
31 }
32
33 @synthesize personName;
34 @synthesize expectedRaise;
35 @end
MyDocument
1 //
2 //MyDocument.m
3 //RaiseMan
4 //
5 //Created by b1mobile on 2/14/11.
6 //Copyright 2011 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "MyDocument.h"
10
11 @implementation MyDocument
12
13 - (id)init
14 {
15 self = ;
16 employees = [ init];
17 return self;
18 }
19
20 - (void)dealloc
21 {
22 ;
23 ;
24 }
25
26 - (void)setEmployees:(NSMutableArray *)a
27 {
28 if(a == employees)
29 {
30 return;
31 }
32
33 ;
34 ;
35 employees = a;
36 }
37
38 - (NSString *)windowNibName
39 {
40 // Override returning the nib file name of the document
41 // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
42 return @"MyDocument";
43 }
44
45 - (void)windowControllerDidLoadNib:(NSWindowController *) aController
46 {
47 ;
48 // Add any code here that needs to be executed once the windowController has loaded the document's window.
49 }
50
51 - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
52 {
53 // Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.
54
55 // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.
56
57 // For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
58
59 if ( outError != NULL ) {
60 *outError = ;
61 }
62 return nil;
63 }
64
65 - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
66 {
67 // Insert code here to read your document from the given data of the specified type.If the given outError != NULL, ensure that you set *outError when returning NO.
68
69 // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead.
70
71 // For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.
72
73 if ( outError != NULL ) {
74 *outError = ;
75 }
76 return YES;
77 }
78
79 @end
页:
[1]