`
mmdev
  • 浏览: 13469404 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

关于寒假学习objective-c的感想

 
阅读更多

买了本《learn objective-c on Mac》,一开始买来看起来还蛮薄的,250页,看了后,发现语言都有很多共同的地方,新的特性都从C++和java类似过来,就是换了个名字,感觉看了以后感觉收获蛮大,虽然只接触了点皮毛。

1.C语言知识

2.了解了xcode使用

3.懂得了一些新语法和新特性。

---------------------------------------------------------------------------------------------

1.正式协议 与 非正式协议(被@optional的正式协议代替) 与文件加载保存

@required 一定要实现

@optional 选择性实现

例1.

@protocol NSCopying //深度复制复制

-(id) copyWithZone:(NSZone*)zone;

@end

NSArray的copy为浅复制

@protocol NSCoding //编码与解码

-(void)encodeWithCoder:(NSCoder*)acoder;

-(id)initWithCoder:(NSCoder*)decoder;

NSCoding可用于将任何对象编码为NSData NSData可用 [data writeToFile:"tmp.txt" atomically:true] 存入硬盘

例1:

通过NSKeyedArchiver类进行编码为NSData

NSData*data=[NSKeyedArchiver archivedDataWithRootObject:对象];自动调用encodeWithCoder

A *a=[NSKeyedUnarchiver unarchiveObjectWithData:data]; //解码

------------------------------------------------------------------------------------------------------------

属性列表 NSArray NSDictionary NSString NSNumber NSDate NSData

1.NSArray

+(id)arrayWithObject:... 以nil结尾

-(unsigned)count;

-(id)objectAtIndex:(unsigned) index;

NSMutableArray

+(id)arrayWithCapacity:(int);

-(void)addObject:(NSObject);

-(void)removeObjectAtIndex:(int)index;

2.NSDictionary

+(id)dicitonaryWithObjectsAndKeys:(id)firstObject,(NSString*)firstkey...;

-(id)objectForKey:(id)key;

NSMutableDictionary

+(id)dicitonaryWithCapacity:(int)n;

-(void)setObject:(id) object forKey:(id)key;

-(void)removeObjectForKey:(id)key;

3.NSNumber

封装标准类型

NSNumber*a=[NSNumber numberWithInt:10];

4.NSDate

+(NSDate*)date;

+(NSDate*)dateWithTimeIntervalSinceNow:(int)a;

5.NSData

+(NSData*)dataWithBytes:(NSObject) length:(int);

-(int)length;

-(NSObject) bytes;

--------------------------------------------------------------------------------------------------------

谓词:

谓词实际上就是用简单的方式给出限制条件 可以用for 和if来替代

NSPredicate:

+(NSPredicate)predicateWithFormat:....

-(NSArray*)filteredArrayUsingPredicate:predicate;

例:

谓词还给了很多的运算符(可以沿用C的运算符)

例:沿用上了例子的类

NSPredicate*predicate=[NSPredicate predicateWithFormat:@"(name=='A')AND(name=='B')"];

数组运算符 name BETWEEN{MIN,MAX};

name IN{"A","B"};

SELF的运用:

NSArray*a=[NSArray arrayWithObject:@"A","B",nil];

NSPredicate*predicate=[NSPredicate predicateWithFormat:@SELF IN "'A','B' "];

NSArray* b=[a filteredArrayUsingPredicate:predicate];

字符串运算符:

BEGINSWITH

ENDSWITH

CONTAINS

[c]忽略大小写

[d]忽略重音符

[cd]都忽略

例: BEGINSWITH[c]

LIKE运算符

LIKE '*A*' 中间包含A即可

LIKE '??A*'前面有两个字符

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics