Katex

2012年9月3日 星期一

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 架構. 明天繼續...


MAC Day 3 : iPhoto

MAC 上的 iPhoto 功能還蠻強大的,今天用到了兩個功能:

1. 相機照片輸入
    直接插入 USB 連接,自動會跳出 iPhoto 軟體來匯入照片

2. 照片 Size 縮小

    (1) 選取要縮小的檔案,接著點選  File (檔案) -> Export (輸出)



會跳出以下的畫面,接著選擇size和輸出檔案位置即可

 

2012年8月29日 星期三

MAC Day 2 : Key




啓動

開機時按下 C從可開機的 CD、DVD 或 USB 隨身碟(如 OS X 安裝媒體)啟動。
開機時按下 D啟動到 Apple Hardware Test (AHT)。
按住 Option-Command-P-R,直到再次聽到啟動聲。重置 NVRAM
開機時按下 Option啟動到 Startup Manager,從這裡,您可以選擇要啟動的 OS X 卷宗。附註:按下 N 也能顯示第一個可開機的網路卷宗。
按下退出鍵、F12,或按住滑鼠或觸控式軌跡板按鈕退出所有抽取式媒體,例如光碟。
開機時按下 N嘗試從相容的網路伺服器(NetBoot)啟動。
開機時按下 T以“目標磁碟模式”啟動。
開機時按下 Shift以“安全啟動”模式啟動,然後暫時停用登入項目。
開機時按下 Command-V以 Verbose 模式啟動。
開機時按下 Command-S以單一使用者模式啟動。
開機時按下 Option-N使用預設的開機映像檔從 NetBoot 伺服器啟動。
開機時按下 Command-R







Command Key







  • Command-A     Edit Menu     Select All - 全選
  • Command-C     Edit Menu     Copy          拷貝
  • Command-S     File Menu     Save           儲存
  • Command-V     Edit Menu     Paste         貼上
  • Command-X     Edit Menu     Cut            剪下
  • Command-Z     Edit Menu     Undo          還原


輸入法切換 :Command + Space
全螢幕拷貝:Command + Shift + 3
選取拷貝:Command + Shift + 4





Option - Option 或 Alt 鍵圖像












Fn :

搭配方向鍵可以變成:Home, End, PageUp, PageDown


Multipad :

雙指上下移動:滾軸
三指向上移動:桌面切換




熱門文章