I have a class named myClass that contains 3 NSInteger and I can’t do a method like that:
- (myClass)getClass {
myClass *class1;
return class1
}
it gives me an error
EDIT: the error is in the .h
- (myClass *)getClass; Error: expected ')' before 'myClass'
I suppose you want to return an instance of
myClass. You can do that like this:If instead you want to return the class itself:
You can change the
-to a+if you want it to be a class method instead of an instance method. Your question wasn’t quite clear.In Objective-C you can never return an object by value, since the size of an object in Objective-C isn’t known at compile time. If you don’t like the asterisks everywhere you can do
typedef myClass* myClassRefand return amyClassRefinstead.