Syntax to return an instance in Objective-C
can u please help me how to return an instance of a function which is inherited through interface in Objective-C Language?
@protocol prot1
{
public IDispManager getDispManager;
}
@end
@interface A: NSObject (prot1)
{
}
@end
@implementation A
{
/**
* Provides access to the disp manager.
* @return Instance of the开发者_如何转开发 disp manager.
*/
public IDispManager getDispManager;
// how to return an instance of this method
}
@end
Plssss help me out???????
The class would have to hold an object of that class and provide a method to return it. Here's an example along the lines of what you wanted to write:
@protocol Proto
- (DisplayManager *)displayManager;
@end
@interface Foo : NSObject <Proto> {
DisplayManager *displayManager;
}
- (DisplayManager *)displayManager;
@end
@implementation Foo
- (DisplayManager *)displayManager {
return [[displayManager retain] autorelease];
}
@end
Though this probably won't make sense to you without understanding the language more fully.
精彩评论