Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

999707 Posts in 39242 Topics- by 30653 Members - Latest Member: alexscottheath

April 24, 2014, 09:01:12 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)An Obj-C Question
Pages: [1]
Print
Author Topic: An Obj-C Question  (Read 2061 times)
Corpus
Guest
« on: November 13, 2008, 04:17:14 PM »

Okay, this is the AppDelegate class interface declaration from the app delegate header file which is standard in Xcode iPhone apps.

Something is really bugging me, and I can't find any answers...
Code:
@interface clacketytankAppDelegate : NSObject <UIApplicationDelegate> { ...

What does the text between the <> brackets mean here?
Logged
Michael Buckley
Level 0
***



View Profile
« Reply #1 on: November 13, 2008, 05:18:33 PM »

The < > brackets indicate that the clacketytankAppDelegate conforms to the UIApplicationDelegate protocol. In Objective-C, protocols are similar to interfaces in Java. They are merely a collection of methods, and a class which conforms to a protocol must implement all of those methods (or have one of its super classes implement those methods. You can specify your own protocol like so:

Code:
@protocol DiscoDancer
- (void)getDown;
- (void)getFunky;
@end

Then, if you want, you can create a method like so:

Code:
- (void)playThatFunkyMusic:(NSObject<DiscoDancer>* aWhiteBoy)
{
    [aWhiteBoy getDown];
    [aWhiteBoy getDown];
    [aWhiteBoy getFunky];
}

When the code is compiled, it will throw a warning if any classes which conform to a protocol don't implement all of its methods, or if an object which does not conform to a protocol is passed into a method like playThatFunkyMusic:.

You can also make an object conform to multiple protocols like so:

Code:
@interface KungFuFighter : NSObject <DiscoDancer, SexGod>

And finally, you can check at runtime if an object conforms to a protocol like so:

Code:
if([aWhiteBoy conformsToProtocol:@protocol(DiscoDancer)]){

All of the above code assumes that you're using Cocoa/NSObject as your base class. If you aren't the code will be a little different. E.g., you'll use conformsTo: instead of conformsToProtocol:. It also assumes you have defined a SexGod protocol somewhere.
Logged
Corpus
Guest
« Reply #2 on: November 14, 2008, 08:38:12 AM »

Thanks, Michael Smiley
Logged
Michael Buckley
Level 0
***



View Profile
« Reply #3 on: November 14, 2008, 12:09:24 PM »

No problem. Glad to help.
Logged
mikehal
Manbaby
*


View Profile
« Reply #4 on: December 29, 2008, 09:56:34 AM »

This a really helpful clarification. Thanks!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic