Katex

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

2012年8月30日 星期四

Mac Day 4 : iphone Hello world - Xcode 4.4


iOS : Start Developing iOS Apps


1. Xcode 4.4 : Create a new Xcode project



2. New Project -> Empty Application


3. Product Name : HelloWorld
    Device : iphone
    勾選 :Use Automatic Reference Counting
                 會自動計算參考個數來決定是否回收記憶體

 
4.  專案位置,並有git的版本控管



5. 樣板程式產生了



6. 主程式 :main.m
    int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

  @autoreleasepool : 支援 Auto reference counting

int UIApplicationMain (
   int argc,
   char *argv[],
   NSString *principalClassName,
   NSString *delegateClassName
);
Parameters
argc
The count of arguments in argv; this usually is the corresponding parameter to main.
argv
A variable list of arguments; this usually is the corresponding parameter to main.
principalClassName
The name of the UIApplication class or subclass. If you specify nil, UIApplication is assumed.
delegateClassName
The name of the class from which the application delegate is instantiated. If principalClassName designates a subclass of UIApplication, you may designate the subclass as the delegate; the subclass instance receives the application-delegate messages. Specify nil if you load the delegate object from your application’s main nib file.
Return Value
Even though an integer return type is specified, this function never returns. When users exits an iPhone application by pressing the Home button, the application moves to the background.
7. AppDelegate.m


(1) 點選 icon 啓動 app




(2) 按下 Home 鍵返回桌面時
applicationWillResignActive:
applicationDidEnterBackgroud:
(3) 再由桌面按 icon 返回 app
applicationWillEnterForegroud:
applicationDidBecomeActive:

在 didFinishLaunchingWithOptions 中加入

    UILabel * helloLabel = [[UILabel alloc]init];
    
    helloLabel.frame = CGRectMake(50, 50, 200, 30);

    helloLabel.text= @"Hello World";
    
    [self.window addSubview:helloLabel];


8. 執行程式


完成. 但是這並不是 Model - View - Control 架構. 明天繼續...


熱門文章