Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C -- is there a keypath that will cause an object to return itself?

Given an object foo of class Foo, I want to do the following:

NSString *key = @"some key";
id myObj = [foo valueForKey: key];

and have myObj equal to foo.

Is there a way to do this without defining a category on Foo?

like image 613
William Jockusch Avatar asked Feb 04 '10 15:02

William Jockusch


2 Answers

The following works for me, returning foo:

id myObj = [foo valueForKey: @"self"];
like image 147
Costique Avatar answered Sep 27 '22 21:09

Costique


id myObj = foo;
like image 30
swegi Avatar answered Sep 27 '22 21:09

swegi