2012年6月26日星期二

Protocol in Extension in Objective C

For cases that a class should implement a Protocol (Interface in some other languages), but may not favorable to be seen by all the class.
A solution could be implementing the protocol at the Category declaration.

For example, I wanna implement the NSXMLParserDelegate in a class but just want the selectors to be
called as delegate.

at .h declaration:
@interface ClassName : NSObject
{
    //sth.....
}
@end

at .m file (or other .h file in some cases) declaring the extension:
@interface ClassName(NSXMLParserDelegate) <NSXMLParserDelegate>
    //some function in the NSXMLParserDelegate protocol.....
@end

@implementation ClassName(NSXMLParserDelegate)
    //do sth...
@end

@implementation ClassName
    //.......
@end

Reference: Stackoverflow

Good UML/Diagram Tools

Just found a handy UML diagram tool on Chrome Web Store - Diagramly.
It is totally free and support syncing with google drive. May not be very professional one but is really amazing for normal use.


Xcode stuck at “Attaching to (app name)”

My project failed to launch after I added a folder reference with the same name as one of the Group of the project.
Xcode didn't prompt me for any errors, but after sometime when I run my app on the simulator the console showed "error: failed to attach to process id 0" to me.

This drove me crazy.
Becoz remove the folder reference doesn't work, and even I opened a new blank project with the same Product Name doesn't work.
I turned to restart my computer and Xcode, used a new Product Name for my new project, and added that folder reference with a different name.

This used almost 3 hours to fix that.......

reference: StackOverflow