I am trying to access an object in an implementation file where the method looks like this: In the main file, It looks legal and everything, but encode complains that there is no such property in this object and no such object exists. Help? Objects with type All you need to do is be more specific: If you have to handle two unequal types of objects, then be a little more secure about it and use - ( Boolean) Human ISLiv: (ID) manpower; However, Xcode complains that such an object is not present and the construction fails.
main.m , I type it in the
main () function:
int main (Int argc, const char * argv []) {NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] INS]; Human * human = [[human alloted] init]; MyHuman * myhuman = [[MyHuman alloc] init]; [Make humans: @ "John Doe" age: 25]; If ([human human is Live: Myhuman]) {NSLog (@ "% @ is alive and well.", Myhuman.humanName); } Other {nslog (@ "% @ is dead and gone"), Myhuman.humanName); } [Pool drain]; Return 0; } Here is the code that complains about Xcode:
- (boolean) man is alive: (id) manpower {if (humanobj .living == Yes) {return yes; } no return; }
id with an instance method on any object Can not be safely solved, so they are denied by language. In addition, if you can add the attribute to
id , then we have spoiled a language.
- (BOOL) humanIsAlive: (MyHuman *) humanobj {// ...}
-isKindOfClass: , then place the object in the place where its properties are used. It is advisable to do
No comments:
Post a Comment