Katex

2012年9月5日 星期三

MAC Day 10 - Objective-c - accessor method


1. .h : @property 宣告實體變數

@property(attribute1, attribute2…) type variable

writability :



readonly
-唯讀,只能讀取而不能設定值(不能用setXXXX的函式)。
readwrite-可讀可寫(預設)。


setter semantics


strong - 


f2 = f1;

[f1 retain];
[f2 release];
f2 = f1;

如果沒有將 f2 release, 可能會造成 memory leak
weak - 


避免 retain cycle. 
在 iOS 4 和 OS 10.6 不支援, 須改用 unsafe_unretained


copy-在設值時copy一份新資料,release舊資料。
assign-在設值時替換新舊資料, 而不會增加 retain count(預設)。
retain-在設值時retain新的資料,release舊資料。

Atomicity

nonatomic-預設為atomic以符合多工環境, 設成nonatomic可提高效率


e.g. 
@property double accumulator;



2. .m : @synthesize 存取實體變數

e.g.
@synthesize accumulator;



3. 則不需要額外函式, 就可以存取變數

e.g.
        [myCalc setAccumulator: 100.0];

        NSLog(@"The result is %g", [myCalc accumulator]);





2012年9月4日 星期二

Mac Day 9 - Objective-C - Xcode - Files


依類別存放檔案

1. File -> New -> File


2.  Objective-C class


3.  輸入 class 名稱


4. create 確定後會產生 .m 和 .h 檔




2012年9月3日 星期一

MAC Day 8 - Objective-C - NSString

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html


stringWithString:

Returns a string created by copying the characters from another given string.
+ (id)stringWithString:(NSString *)aString

e.g.     newStr = [NSString stringWithString: oldStr];

UTF8String

Returns a null-terminated UTF8 representation of the receiver.
- (const char *)UTF8String

e.g     NSLog(@"newStr: %s", [newStr UTF8String]);



MAC Day 7 - Objective C - 記憶體管理

1. 自動垃圾回收 Automatic Garbage Collection
2. 手動引用計數 Manual Reference Counting, MRC
3. 自動引用計數 Automatic Reference Counting, ARC

和 Java 很像, Garbage Collection 用 reference counting 來看該塊記憶體有沒有程式使用.
如果沒有就將其透過 release pool 回收.

4. 自動釋放池 Auto release pool
    @autoreleasepool


    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 
    NSLog(@"Hello World!");
 
    [pool drain];


=>


    @autoreleasepool{
        NSLog(@"Hello World!");
    }


5. retain v.s. release
    retain : reference count + 1
    release : reference count -1

2012年9月2日 星期日

MAC Day 6 - Objective C - Hello World

Objective C 是 Brad J. Cox 在 1980 所設計的程式語言, 以 SmallTalk 80 為基礎.
1988 年授權給 NeXT.
1992 年 加入 GNU
1996 年 Apple 將其作為主要的開發語言

Objective C 本身是 C 的延伸語言, 所以原本的 C 程式可以在 Objective-C 上編譯.
以 Xcode 來開發實驗 :

1. Create new project :
     選擇 OS X -> Application, Command Line Tool, 就可以在 MAC 上面執行



2. Options Type : Foundation



3. 進入 IDE 環境後, 修改程式為 C 來試試 :



//#import

#include

int main(int argc, const char * argv[])
{
    
    printf("Hello, World!");

/*
    @autoreleasepool {
        
        // insert code here...
        NSLog(@"Hello, World!");
        
    }
*/
    return 0;
}




原本程式執行結果


改為 C 語言後執行結果


2012年9月1日 星期六

Mac Day 5 : Xcode - install

0. App Developer
    https://developer.apple.com/

1. 下載 Xcode
    https://developer.apple.com/xcode/
    可從 App Store 下載,此為免費軟體


  安裝時原本不曉得狀態,原來在底部的 Launchpad 可以看到




2. 安裝好了,可以來使用囉



 







電影 : 羅馬浴場

羅馬浴場
Thermae Romae

- 阿部寬 / 上戶彩



這部電影是出自漫畫家山崎麻里在 2008 年的同名作品, 故事發自古羅馬人浴池技師 路西斯 來回穿越 古羅馬與現代日本時空 而帶來的笑料與衝擊, 是 <<電車男>> 導演 武內英樹 與 編劇 武藤將吾 再次攜手合作的作品. 在選角上, 由身高 189, 輪廓深邃的阿部寬 來詮釋 羅馬人 路西斯 真是太恰當了, 阿部寬這位冷面笑將, 遇到驚奇的事物,嚴肅地睜大眼睛,陷入沈思,和漫畫如出一轍



    上戶彩與阿部寬自 2002 年的電視劇 <<甜心小廚師>> 後再度攜手合作.









 



羅馬浴場》官方FB:
http://www.facebook.com/ifilm.tw
官方BLOG:http://ifilm.pixnet.net/blog

熱門文章