整合登機證,儲值卡,電影票,貴賓卡....
Katex
2012年9月9日 星期日
2012年9月8日 星期六
2012年9月7日 星期五
MAC Day 12 - Objective C - Class
和 C / C++ 不同地方
1. #import
是當初 C: #include 的改良版, 保證標頭檔只會被匯入一次
換言之, 標頭檔 就不用寫成像 :
2. @autoreleasepool
3. 物件
C++:
Objective C:
[ ClassOrInstance method ];
myDog = [Dog new];
[myDog run];
4. Interface
@interface NewClassName : ParentClassName
propertyAndMethodDeclarations;
@end
+: 類似於 C++ : static function
5. Implementation
@implementation NewClassName
{
memberDeclarations;
}
methodDefinitions;
@end
6. NSObject
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html
7. program
1. #import
是當初 C: #include 的改良版, 保證標頭檔只會被匯入一次
換言之, 標頭檔 就不用寫成像 :
#ifndef _XXX_H_
#define _XXX_H_
...
#endif
而可以直接宣告
2. @autoreleasepool
3. 物件
C++:
obj->method(argument);
Objective C:
[obj method: argument];
[ ClassOrInstance method ];
myDog = [Dog new];
[myDog run];
4. Interface
@interface NewClassName : ParentClassName
propertyAndMethodDeclarations;
@end
@interface MyObject : NSObject
+(return_type) class_method; // 類方法 -(return_type) instance_method1; // 實體方法 -(return_type) instance_method2: (int) p1; -(return_type) instance_method3: (int) p1 andPar: (int) p2;
@end
+: 類似於 C++ : static function
5. Implementation
@implementation NewClassName
{
memberDeclarations;
}
methodDefinitions;
@end
@implementation MyObject{ int memberVar1; // 實體變數 id memberVar2; }+(return_type) class_method { .... //method implementation } -(return_type) instance_method1 { .... } -(return_type) instance_method2: (int) p1 { .... } -(return_type) instance_method3: (int) p1 andPar: (int) p2 { .... } @end
6. NSObject
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html
7. program
@interface Dog: NSObject
-(void) print;
-(void) setName: (NSString*) name;
@end
@implementation Dog
{
NSString *name;
}
-(void) print {
NSLog(@"%@", name);
}
-(void) setName: (NSString*) n {
name = n;
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
Dog *myDog;
NSString *name = @"WonWon";
myDog = [Dog new];
[myDog setName: name];
NSLog(@"My dog's name is");
[myDog print];
}
return 0;
}
2012年9月6日 星期四
MAC Day 11 : objective-c : try catch
1. catch
@try {
|
... |
} |
@catch (CustomException *ce) { // 1
|
... |
} |
@catch (NSException *ne) { // 2
|
// Perform processing necessary at this level. |
... |
} |
@catch (id ue) {
|
... |
} |
@finally { // 3
|
// Perform processing necessary whether an exception occurred or not. |
... |
} |
2. throw
SException *exception = [NSException exceptionWithName: @"HotTeaException" |
reason: @"The tea is too hot" |
userInfo: nil]; |
@throw exception; |
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日 星期二
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]);
訂閱:
文章 (Atom)
熱門文章
-
星宇航空 - 空中巴士 A350-900 網站這邊有個 3D 預覽 https://media.starlux-airlines.com/mandarin/a350/3d-cabinview/ 星宇航空的機型代號「359」指的是空中巴士A350-900。 在航空業中,A350...
-
(圖 by Midjourney) 深淵求索 - Deepseek 之道列表 僅為紀錄非投資建議 投資有風險, 買賣請小心 投資は自己責任でお願いします -- 續篇反轉請看: AI 日圓外匯交易團隊會議記錄 - 2026.2.16 (內有 Github 網址, 之後放到 Gi...









