This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[myObj setValue:@"peter" forKey:@"name"]; | |
(1) 呼叫 setName: | |
(2) 如果setName:不存在,存取instance variable name。 | |
NSLog(@"name %@", [mutableArray valueForKey:@"name"]); | |
回傳array,array裡為對mutableArray裡的每個物件呼叫valueForKey:的結果。 | |
ex: | |
-> | |
name ( | |
Peter, | |
Wendy | |
) | |
Artist *artist = [[Artist alloc] init]; | |
Album *album = [[Album alloc] init]; | |
[artist setValue:album forKey:@"newAlbum"]; | |
[artist setValue:@"怎麼開始忘了" forKeyPath:@"newAlbum.name"]; | |
NSLog(@"album name %@", [artist valueForKeyPath:@"newAlbum.name"]); | |
利用keyPath,可以串聯 | |
沒有留言:
張貼留言