Snapples
asked on
Querstion about id
Hey experts,
I'm rather new to iOS and objective-C and I'm making the transition from C++ and C#, so please bear with me.
I was wondering if anyone could explain the id type to me. So far I know that id is kind of comparable to var, as that it can be any type. But I don't quite understand how it's being used in this piece of code below, which is from the example project Elements that comes with Xcode.
ElementsDatasource is a protocol (which I'm still figuring out so if anyone could explain that to me in simple terms I'd be really grateful too). In this example, what kind of object can theDataSource be?
Thanks in advance.
I'm rather new to iOS and objective-C and I'm making the transition from C++ and C#, so please bear with me.
I was wondering if anyone could explain the id type to me. So far I know that id is kind of comparable to var, as that it can be any type. But I don't quite understand how it's being used in this piece of code below, which is from the example project Elements that comes with Xcode.
ElementsDatasource is a protocol (which I'm still figuring out so if anyone could explain that to me in simple terms I'd be really grateful too). In this example, what kind of object can theDataSource be?
Thanks in advance.
- (id)initWithDataSource:(id<ElementsDataSource,UITableViewDataSource>)theDataSource {
if ([self init]) {
theTableView = nil;
// retain the data source
self.dataSource = theDataSource;
// set the title, and tab bar images from the dataSource
// object. These are part of the ElementsDataSource Protocol
self.title = [dataSource name];
self.tabBarItem.image = [dataSource tabBarImage];
// set the long name shown in the navigation bar
self.navigationItem.title=[dataSource navigationBarName];
// create a custom navigation bar button and set it to always say "back"
UIBarButtonItem *temporaryBarButtonItem=[[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title=@"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
}
return self;
}
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER