OC學習總結(一)
OC學習總結(一)
知識要點
1、 類(interface)
》標頭檔案格式.h
@interface class-name : super-class-name <protocol-name,...>{
@private
instance variable
...
@public
...
@protected(default)
...
}
@property ... //點語法中可以方便使用
//xcode4.4以後property關鍵字實現了三部分工作:成員變數的定義如_name(預設為private),property和synthesize的功能
//構造方法的命名約定(以Person類為例):類方法personWith開頭,例項方法initWith開頭
//+開頭的類方法
//-開頭的例項方法
@end
》實現檔案.m(.mm)
@implementation class-name
@synthesize ... //點語法中可以方便使用
//實現方法
...
@end
2、 分類(Category)
》標頭檔案格式.h
@interface class-name (category-name)
//+開頭的類方法
//-開頭的例項方法
@end
》實現檔案.m(.mm)
@implementation class-name (category-name)
//實現方法
...
@end
3、 協議(Protocol)
》標頭檔案格式.h
@protocol protocol-name
//協議方法
...
@end
4、 擴充套件(Extension)
》宣告和實現都在.m檔案中
》格式類似於無名Category
@interface class-name ()
@end
》實現在原有類的implementation中
》相當於私有方法,類內部才可用
5、 委託(Delegate)
》協議的一大特色,代理模式
》協議FindHouse的定義
@protocol FindHouse
- (void) findHouse;
@end
》代理中介Agent
@interface Agent : NSObject <FindHouse>
- (void) findHouse;
@end
》甲方Person
@interface Person : NSObject{
id<FindHouse> delegate; //實現了FindHouse協議的物件都可以作為代理
}
+ (id) personWithDelegate:(id<FindHouse>)pDelegate; //注入代理
- (void) startToFindHouse;
@end
6、 Foundation框架
》NSNumber(涉及到基本資料型別和物件的相互轉化,包裝和拆包)
包裝[Number numberWithInt:age]
拆包[number intValue]
》NSString(字串的初始化、拼接、查詢和比較)
字面量語法 NSString *str = @"hello oc"
長度[str length]
子串substringFrom, substringTo, substringWithRange
比較isEqualToString, compare, caseInsensitiveCompare
拆分字串 componentsSeparatedByString
陣列拼接字串componentsJoinedByString
字串拼接stringWithFormat
查詢字串hasPrefix, hasSuffix, containsString, rangeOfString
》NSArray(陣列中只能存放物件,包括可變NSMutableArray和不可變陣列)
建立arrayWithObjects, arrayWithArray
長度[arr count]
查詢indexOfObject
可變陣列addObject
》NSSet(無序列表,只能存放物件,分類可變NSMutableSet和不可變集合,自動去除重複物件)
建立setWithObjects
增加setByAddingObject(返回新物件)
可變集合NSMutableSet
子集判斷intersectsSet
交集intersectSet
差集minusSet
》NSDictionary(字典為鍵值對,鍵值都必須是物件,而且都不能為nil,如果值為空時可採用NSNull)
建立dictionaryWithObjectsAndKeys
取值objectForKey
可變字典 setValue: forKey
刪除removeObjectForKey
版權宣告:本文為博主原創文章,未經博主允許不得轉載。
相關文章
- Python學習第一週學習總結Python
- Spring Cloud學習總結(一)SpringCloud
- Kotlin 基礎學習總結(一)Kotlin
- 學習總結
- iOS底層原理總結--OC物件的本質(一)iOS物件
- 學習 CodeWhisperer 的一些總結
- Python str型別學習總結(一)Python型別
- ConstraintLayout 學習總結AI
- BOM學習總結
- tkinter學習總結
- vue學習總結Vue
- HSF學習總結
- ElasticSearch 學習總結Elasticsearch
- Storm學習總結ORM
- vue 學習總結Vue
- lua 學習總結
- Angularjs 學習總結AngularJS
- WebRTC學習總結Web
- GCD 學習總結GC
- CompletableFuture學習總結
- awk 學習總結
- MyBatis 學習總結MyBatis
- Maven學習總結Maven
- Ajax學習總結
- JVM學習總結JVM
- mysqlimport學習總結MySqlImport
- WorkFlow學習總結
- JNI 學習總結
- SVG學習總結SVG
- HTML學習總結HTML
- Mybatis學習總結MyBatis
- JavaWeb學習總結JavaWeb
- KUDU學習總結
- pandas 學習總結
- fetch學習總結
- MYSQL學習總結MySql
- 近期學習總結
- 【TS】學習總結
- SpringCloud 學習總結SpringGCCloud