7

Let's assume we have an object of type person, which has a property called name.

Person *p;
[p setValue:@"John" forKey:@"name"];

This works very nicely. What I want to do is dig deeper. Say the class person has another property called address which is of class Address and has a field called zipcode.

Is there a simpler way of assigning the zipcode from the person than this? Maybe something cleaner and clearer?

[[p valueForKey:@"address"] setValue:@"234567" forKey:@"zipcode"];

1 Answer 1

6

The keyPath should fit you requirements.

[p  setValue:@"234567" forKeyPath:@"address.zipcode"];

Check doc NSKeyValueCoding Protocol and Key-Value Coding Fundamentals

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.