Objective-C on the Mac L26 - Key-Value Coding

preview_player
Показать описание
How to use Key-Value Coding (KVC) to set and get values in Objective-C.
Рекомендации по теме
Комментарии
Автор

Is this perfect or what? I just got to the point where I had to learn more about KVC and then this is released! Perfect! Thank you!

mattiashedman
Автор

@mattiashedman You're very welcome, we will have some Key-value observing tutorials this week as well.

AppleProgramming
Автор

@iFaisalCs If the item has a mutable subclass, it is best to use copy instead of retain. I messed that up when I did the original properties video. Basically if you don't copy a class that has a mutable subclass (NSString has NSMutableString), then you could end up changing the value of the string you set accidentally if you set it to a mutable version. Not likely to happen but it can. I should have explained that earlier and I might do a video to correct it later. Great question.

AppleProgramming
Автор

@richardlipp21 I showed the dictionary example just as a way that you can extract multiple values using KVC. You also wouldn't get anything if you printed the "me" object (other than it's address) because the description method was never overridden to print out those values. You can see a better use for KVC in the Cocoa tutorials.

AppleProgramming
Автор

@Techn0Junki3 KVC becomes way more powerful in Cocoa, especially when we add key-value observing. This technology makes up Cocoa bindings, but there is more to learn then what we have here.

AppleProgramming
Автор

@AppleProgramming That sound just perfect! Looking forward to them!

mattiashedman
Автор

@Nudungu Anytime you have a class that has a mutable sublass (NSString has NSMutableString), it's a good idea to copy it. If you passed in a mutable subclass, you could change the values accidentally after setting the value with a retained NSString property.

AppleProgramming
Автор

if i use retain instead of copy attribute then what is the diffrence, can u describe it plz?

danishahmad
Автор

Hello I know this is an old question but anyway .... since I don't remember when you can explicitly instantiate an array of objects, and the statement would look like this :
[me dictionaryvalueforkeys:@[@"nam­e", @"age"]] and so on.

JulianAndresGuarinReyes
Автор

why use using copy rather than retain ?

iFaisalCs
Автор

shoot i got a weird deprecated message

b
Автор

you wouldn't actually be changing the variables in the object, your just creating a separate dictionary.

DrEnginerd
Автор

This seems rather complicated for something seemingly simple (getting and setting)

DrEnginerd
Автор

Great tutorial, but it was unneccesarily too long. Could have been covered in 3 minutes IMO

nikhilverma