On 18 Feb 2011, at 3:07 PM, David Rowland wrote: > I have my appdelegate set up as the delegate for the accelerometer, > > @interface GLSpriteAppDelegate : NSObject <UIApplicationDelegate, > UIAccelerometerDelegate> { ... > When I compile I get alerts like this, > > GLSpriteAppDelegate *appDelegate = [[UIApplication sharedApplication] > delegate]; > type 'id <UIApplicationDelegate>' does not conform to the > 'UIAccelerometerDelegate' protocol
At that line of code, the compiler knows GLSpriteAppDelegate "conforms" to UIAccelerometerDelegate only because it has seen the header that declares that it implements that protocol. Similarly, what it knows about [[UIApplication sharedApplication] delegate] is what it has seen from the headers: That the returned object is an id that implements UIApplicationDelegate; it doesn't know anything else about the object that -delegate may or may not happen to return. Because the type is id, the compiler is happy to do the assignment, _except_ that the protocols for your appDelegate variable and what -delegate returns don't match up. Do this to show that you know what's going on: GLSpriteAppDelegate *appDelegate = (GLSpriteAppDelegate *)[[UIApplication sharedApplication] delegate]; > Second oddity. If my implementation looks like this, note the semicolon at > the end, > > - (void)accelerometer:(UIAccelerometer *)accelerometer > didAccelerate:(UIAcceleration *)acceleration; > { > etc. etc. > > Everything behaves just the same. I would have thought the semicolon would be > a syntax error, but the compiler doesn't even issue an alert. Objective-C has always tolerated a semicolon at the end of a method header. It's so you can copy all the declarations into your implementation without editing. — F _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com