NSArrayController(Chapter 8 of Cocoa Programming for Mac OS X)

ExpandedBlockStart.gif Person
 1  #import  " Person.h "
 2 
 3 
 4  @implementation Person
 5 
 6  -  (id)init
 7  {
 8      [super init];
 9      expectedRaise  =   5.0 ;
10      personName  =   @" New Person " ;
11       return  self;
12  }
13 
14  -  ( void )dealloc
15  {
16      [personName release];
17      [super dealloc];
18  }
19 
20  -  ( void )setNilValueForKey:(NSString  * )key
21  {
22       if ([key isEqual: @" expectedRaise " ])
23      {
24          [self setExpectedRaise: 0.0 ];
25      }
26       else  
27      {
28          [super setNilValueForKey:key];
29      }
30 
31  }
32 
33  @synthesize personName;
34  @synthesize expectedRaise;
35  @end

 

ExpandedBlockStart.gif 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  =  [super init];
16      employees  =  [[NSMutableArray alloc] init];
17       return  self;
18  }
19 
20  -  ( void )dealloc
21  {
22      [super setEmployees:nil];
23      [super dealloc];
24  }
25 
26  -  ( void )setEmployees:(NSMutableArray  * )a
27  {
28       if (a  ==  employees)
29      {
30           return ;
31      }
32      
33      [a retain];
34      [employees release];
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      [super windowControllerDidLoadNib:aController];
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  =  [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
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  =  [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
75      }
76       return  YES;
77  }
78 
79  @end

 

 

转载于:https://www.cnblogs.com/zhtf2014/archive/2011/02/14/1954579.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值