Thursday, August 21, 2008

Lac [k] of updates

Hey!!!!

Sorry for the lack of updates but I'm recently very very busy in things that I'm forced to do such as homework!!

Anyways, let me tell you that I'm becoming an XML expert. That's right. Hopefully by the end of the month I'll have everything ready. Web Services + Java + iPhone SDK (mobile application)

:)

See you around!!
-igo

Wednesday, July 23, 2008

Protocol Objects?

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.

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

Workplace

Sharing my workplace. Thanks JackBe

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.

Sunday, July 20, 2008

Runtime Differences

"Non-fragile instance variables"? Wow....haha, 64bits is giving me headaches!!

Monday, June 30, 2008

Happy Objective-C

I love Obj-C :D

What I learnt in today's reading:

NSObject - superclass of everything except your own root class [way difficult]

Classes as the object factory since each object is an instance of a class, therefore it's a class object.

Some similarities between instanceof and isMemberOfClass:someClass method.
and isKindOfClass:someClass method which tells if the object we are evaluating inherits from someClass.


Static Typing (ohh pointers here we go!) Useful for the compiler to do type checking

Rectangle *myRect <- This specifies that myRect is a pointer to Rectangle class and Graphic *myRect is also valid since Rectangle inherits from Graphic, therefore it can be statically typed like that.

Class Objects
The body of our object, meaning the method implementations, name of the class and superclasses, instance variables, declarations of methods and their return types.

Class can be typed id or to the Class data type

id aClass = [anObject class] or Class aClass = [anObject class]

Main function: to create new instances.

id myRect;
myRect = [Rectangle alloc];

what alloc method does is to dynamically allocate memory for the new object's instance variable and initializes them all to 0. But we've got to initialize even properly, not just to 0. ( there we go!!)

What we do to initialize is to surround the alloc with init, like this:

id myRect;
myRect = [[Rectangle alloc] init];

Just then myRect would be able to start interacting (e.g. receive messages). The structure is:
alloc returns an instance of Rectangle
init is performed by that instance to set its initial state

I knew I was inside the matrix!! There is a NSMatrix object!!

Messages rock! Look at this:

[myMatrix setCellClass:[NSButtonCell class]];
so what does this mean? (you can answer, you've learnt all the way with me!)
No clue? Well here it is...
NSButtonCell class returns what? A Class or an Id type therefore that is sent to setCellClass which is a setter to myMatrix NSMatrix object (previously initialized). Clear? No? One more time:
myMatrix is an object (instance) of NSMatrix. The CellClass that will be filling that myMatrix object is being defined by the Class passed to the setter method, NSButtonCell.

Class names can only be used in two ways. As part of a message (receiver) or as a type name for a kind of object. Since I've already explained this you should know it.

One new thing would be that if you don't know the class name at compile time but you will at runtime then use NSString *className
and create this monster:

[anObject isKindOfClass:NSClassFromString(className)]
So what does the last statement means?

That's it for today and you've got homework!!