Not again!!
Now Protocol Objects it seems this never stops. The objects created by protocols (seen earlier) just creates more mess since they are instances of Protocol Class!! Now who did that?!!
Special way of calling them:
Protocol *myXMLSupportProtocol = @protocol(MyXMLSupport);
Adopting protocols?
Yep, "A class is said to adopt a formal protocol if in its declaration it lists the protocol within angle brackets after the superclass name":
@interface ClassName : ItsSuperClass <>
2 or more would be comma-separated inside angle brackets. Categories do basically the same, just use the category declaration and still add the angle brackets with the protocol list
If a class adopts a Protocol the it conforms it. This said, check how it's done.
if ( ! [receiver conformsToProtocol:@protocol(MyXMLSupport)] ) {
// Object does not conform to MyXMLSupport protocol
// If you are expecting receiver to implement methods declared in the
// MyXMLSupport protocol, this is probably an error
}
Enough adopt and conform...let's move on.
Wednesday, July 23, 2008
Who said Event?
Finally we are approaching to code which manages events...such as MOUSE!! (which in this case would be "finger" perhaps? )
When I first saw Protocols at the index I thought of network connections and sockets. Go no go...
"Protocols declare methods that can be implemented by any class"
bottomline
"As an outsider, all you need to know is what messages you can send (the protocol) and where to send them (the receiver)"
All this is to let the anonymous objects live. We need to call other objects but with just don't know what do they expect from us to obtain a value. Basically we do not care if it's a zebra object we are asking something too. I just want that [zebra] object to send me how many stripes he has and where to send that answer. That's all. That's why we need protocols...to know how many stripes the zebra has and where will the answer will be sent, although we don't even know that we are "talking" to a zebra object.
Definition of a protocol (formal)
@protocol devngoProtocl
method declaration
@end
There is the possibility to define between optional and required methods to the user.
(informal)
@protocol NSObject (devngoProtocol) <--- Which shows the usage of categories for this declaration.
@end
When I first saw Protocols at the index I thought of network connections and sockets. Go no go...
"Protocols declare methods that can be implemented by any class"
bottomline
"As an outsider, all you need to know is what messages you can send (the protocol) and where to send them (the receiver)"
All this is to let the anonymous objects live. We need to call other objects but with just don't know what do they expect from us to obtain a value. Basically we do not care if it's a zebra object we are asking something too. I just want that [zebra] object to send me how many stripes he has and where to send that answer. That's all. That's why we need protocols...to know how many stripes the zebra has and where will the answer will be sent, although we don't even know that we are "talking" to a zebra object.
Definition of a protocol (formal)
@protocol devngoProtocl
method declaration
@end
There is the possibility to define between optional and required methods to the user.
(informal)
@protocol NSObject (devngoProtocol) <--- Which shows the usage of categories for this declaration.
@end
Tuesday, July 22, 2008
iPhoneFirst
Hey!
Although I haven't finished the Obj-C guide I headed to the example. I just couldn't bear it anymore.
XCode basically does everything for us. I just displayed the nice Hello World!.
Simple commands so to speak:
Delegate:
MyView *view = [[MyView alloc] initWithFrame:[window frame]];
[window addSubview:view];
[view release];
View:
- (void)drawRect:(CGRect)rect {
/* Draw "Hello, World!" */
NSString *hello = @"Hello, World!";
CGPoint location = CGPointMake(30, 30);
UIFont *font = [UIFont systemFontOfSize:24];
[[UIColor whiteColor] set];
[hello drawAtPoint:location withFont:font];
}
Yes, it is an instance method. We can more or less know what the snippet tells right? We've got the casting method, declaring @"" as String and so on. Perhaps the doubt is
CGPoint location = CGPointMake(30, 30);
why? Where is the *? Perhaps it ain't a pointer and it is in fact some sort of common object assignation.
That'd be all. I'll keep reading now.
One last thing...how can I do this when everyone isn't asleep. I should be resting my 8 hours but then I feel useless since I didn't give it a try the whole day.
Although I haven't finished the Obj-C guide I headed to the example. I just couldn't bear it anymore.
XCode basically does everything for us. I just displayed the nice Hello World!.
Simple commands so to speak:
Delegate:
MyView *view = [[MyView alloc] initWithFrame:[window frame]];
[window addSubview:view];
[view release];
View:
- (void)drawRect:(CGRect)rect {
/* Draw "Hello, World!" */
NSString *hello = @"Hello, World!";
CGPoint location = CGPointMake(30, 30);
UIFont *font = [UIFont systemFontOfSize:24];
[[UIColor whiteColor] set];
[hello drawAtPoint:location withFont:font];
}
Yes, it is an instance method. We can more or less know what the snippet tells right? We've got the casting method, declaring @"" as String and so on. Perhaps the doubt is
CGPoint location = CGPointMake(30, 30);
why? Where is the *? Perhaps it ain't a pointer and it is in fact some sort of common object assignation.
That'd be all. I'll keep reading now.
One last thing...how can I do this when everyone isn't asleep. I should be resting my 8 hours but then I feel useless since I didn't give it a try the whole day.
Sunday, July 20, 2008
Subscribe to:
Posts (Atom)
