SlideShare a Scribd company logo
Really Simple Cocoa Tips
(But save your life!)
by yllan, Sept. 13, 2007
Coverage
Common mistakes.
Handy code snippets.
Tools setting / hotkey / usage.
目的:節省生命!
Compile Cocoa using gcc
gcc something.m -o something -framework Cocoa
Save: 2 hours of try & error
[[NSObject alloc] init]
簡寫! [NSObject new]
Save: 2 secs each time
NSString, 中文?
Save: 2 hour in your life
NSString, 中文?
NSString *s = @”中文” ????
Save: 2 hour in your life
NSString, 中文?
NSString *s = @”中文” ????
Tiger 還不能 樣寫...
Save: 2 hour in your life
NSString, 中文?
NSString *s = @”中文” ????
Tiger 還不能 樣寫...
NSString *s =
[NSString stringWithUTF8String: “中文”];
Save: 2 hour in your life
NSString, 中文?
NSString *s = @”中文” ????
Tiger 還不能 樣寫...
NSString *s =
[NSString stringWithUTF8String: “中文”];
更好的辦法是放在 Localized Resource 裡!
Save: 2 hour in your life
NSLog, 中文?
猜猜 個程式的 Output 是啥:
#import <Cocoa/Cocoa.h>
int main() {
	 NSAutoreleasePool *pool = [NSAutoreleasePool new];
	 NSLog(@"%@", @"Hello, world.");
	 NSLog(@"%@", [NSString stringWithUTF8String: "世界你好"]);
	 NSLog(@"%@", [NSString stringWithUTF8String: "お元気ですが?"]);
	 NSLog(@"%@", [NSString stringWithUTF8String: "bonjour."]);
	 [pool release];
	 return 0;
}
NSLog, 中文?(續)
直接用 fprintf 或者確保包含英文
字元!
Save: 5 hours of debugging
Accessor?
Xcode Script Menu!
TextMate:
acc
stracc
objacc
Save: 5 mins each time
tab
tab
tab
在純文字程式使用 Cocoa 畫圖
Save: 3 hours of googling
在純文字程式使用 Cocoa 畫圖
NSApplicationLoad()
Save: 3 hours of googling
NSImage 在迴圈中生成
Autorelease 物件讓記憶體爆 !
Save: 1 hour of debugging, 5 mins for googling
NSImage 在迴圈中生成
Autorelease 物件讓記憶體爆 !
Save: 1 hour of debugging, 5 mins for googling
NSImage 在迴圈中生成
Autorelease 物件讓記憶體爆 !
Save: 1 hour of debugging, 5 mins for googling
Xcode Speedup
Save: 2 secs each time
Xcode Speedup
Turn it off!
Save: 2 secs each time
Xcode Hotkey
opt esc+
Xcode Hotkey
opt esc+
Auto-Complete
Save: 10 secs each time
Xcode Hotkey
opt esc+
Auto-Complete
ctrl .+
Cycle-Through
Save: 10 secs each time
Xcode Hotkey
ctrl /+
Jump to next placeholder
Save: 1.5 secs each time
Xcode Hotkey
opt shift⌘ ? = Help
⌘
opt
= Jump to definition /
declaration
= Look up in Apple
Reference Library
Save: 10 secs each time
__MyCompanyName__ ?
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions
'{ "ORGANIZATIONNAME" = "My Company";}'
or edit:
/Library/Application Support/Apple/Developer Tools
Save: 1 mins for googling OR 4 hours of searching your HD manually
Interface Builder
控制元件太多?疊在一起
很難選到想要的?別忘了
有 Hierarchy View:
Save: 1 min
Interface Builder
Resize:
曳時按著 Ctrl 可讓 Resize 遵守彈簧設定!
Save: 30 secs each time
Interface Builder
Make Subview of...
Save: 5 mins of try & error
Interface Builder
Make Subview of...
Save: 5 mins of try & error
Interface Builder
Make Subview of...
Save: 5 mins of try & error
Interface Builder
Hotkey 超有用!
⌘ 1∼5
Save: 3.1415926 secs each time
FileMerge
可以比對兩個目錄的不同之處!
Save: 10 minutes each time
FileMerge
可以比對兩個目錄的不同之處!
Save: 10 minutes each time
FileMerge
可以比對兩個目錄的不同之處!
Save: 10 minutes each time
Thank You!

More Related Content

Really Simple Cocoa Tips (2007)