tags:

views:

90

answers:

1

Hi, 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???????

+3  A: 

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.

Chuck
Thnaks a lots... i've understood most of ur code... hey 1 more question... 5th line in ur code i.e [DisplayManager *displayManager;] , can u plz say me what does the line do?if i'm not wrong is it a object of class DisplayManager??? and @class is to be mentioned as @interface in Objective-C right? correct me if i'm wrong.
suse
That line declares an instance variable of the class Foo that points to an object of class DisplayManager. It would have to be set in the class initializer or at some other point. And you're right, `@class` should have been `@interface`. Careless mistake on my part. Sorry about that.
Chuck
ok .. (1)Can @protocol, @interface come in a single file.. i.e in .h file?? and @implementation in .m file... ??? is it a proper coding method??? (2)And also plz tel me can i package all my @protocol as a single package and access it in which ever @interface i need ??? I use to do it in Java but i don knw the procedure to package in Objective-C. or else should i cont by writing as i mentioned in 1st point..??
suse
plssssss reply....
suse
Yes, you can place class interfaces and protocols in the same header file. As for packaging, Objective-C does not have any such concept of "packages". Code is stored in files, not packages. You can put multiple headers into one file, or you can put them into individual files and have one "master" file that imports them all (which is how it's usually done). Generally it's best to try to group things logically.
Chuck
Thanks a lots...
suse
Can u do me a favour ?? Can u send some links of example source code of Objective-C projects written for iPhone OS?Any open source based. I just want to get an idea hw a project is written and how the instances are being used...
suse
tats ok ...........:(
suse
Chuck
ok ...As U mentioned before tat Objective-C does not have any concept of "packages",then wat is *.framework in Targets folders in XCode.its symbol is like a package... i've a snapshot of it for more clearer understanding... but dont knw how to copy it in Stack overflow ....
suse
@suse: Frameworks are an OS X way of grouping libraries and related files together. I guess you can view them as being like packages, but they exist at the filesystem level, not the language level. In order to do something like `import foo.bar.*`, you need to create a header that imports all the relevant files in the framework and import that. At any rate, I wouldn't create a framework unless you really have a large, coherent collection of classes and related resources. Because it's a PITA and you're usually better off just with loose source files in a version control repo.
Chuck