Sunday, 15 April 2012

objective c - objc object pointing -


I am trying to access an object in an implementation file where the method looks like this: - ( Boolean) Human ISLiv: (ID) manpower; However, Xcode complains that such an object is not present and the construction fails.

In the main file, 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; }   

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 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.

All you need to do is be more specific:

  - (BOOL) humanIsAlive: (MyHuman *) humanobj {// ...}   

If you have to handle two unequal types of objects, then be a little more secure about it and use -isKindOfClass: , then place the object in the place where its properties are used. It is advisable to do

No comments:

Post a Comment