標籤:
//// ViewController.m// OC高效率52之瞭解OC起源//// Created by Zoujie on 15/10/8.// Copyright ? 2015年 Zoujie. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // 第一條OC語言的起源 #pragma mrak 要點// OC為C語言添加了物件導向的特性,是其超集。理解C語言的核心概念有助於寫好OC程式。尤其記憶體模型和指標 // 使用"訊息結構"(messaging structure)而非"函數調用"(function calling) // Message (OC) // Object *obj = [Object new]; // [obj performWith:parameter1 and:parameter2]; // Function calling (C++) // Object *obj = [new Object]; // obj ->perform(parameter1,parameter2);#pragma mark 關鍵區別// 1.使用訊息結構的語言,其運行時所應執行的代碼由運行環境來決定; runtime componet// 2.使用函數調用的語言,則由編譯器決定;compile time NSString *someString = @"The String";//此變數指向NSString 的指標 NSString *anotherString = someString; // 對象所佔記憶體總是分配在堆空間中,而絕不會分配在 棧 上。// 有時會遇到定義不含*的變數,他們可能使用 棧空間 這些變數不是OC對象 ,比如CGRect;於建立結構體相比,建立對象還需要額外開銷; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
OC高效率52:(一)瞭解OC起源