凯发k8官方网
收集整理的这篇文章主要介绍了
objective-c 2.0的字面量literals
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
obj-c 2.0增加了许多核心对象字面量的简单语法,向ruby学习吗?
直接上代码:
#import int main(
void){@autoreleasepool{
nsstring *str0 = @
"hello";
nsstring *str1 = [
nsstring stringwithformat:@
"%@",@
"hello"];
nslog(@
"%@ %@",str0,str1);
if(str0 == str1)
nslog(@
"str0 == str1");
if([str0 isequal:str1])
nslog(@
"str0 equal str1");
if([str0 compare:str1] == nsorderedsame)
nslog(@
"str0 compare str1 is same");nsmutableset *set = [nsmutableset new];
nslog(@
"count %lu at begin",[set count]);[set addobject:str0];[set addobject:str1];[set addobject:[str0 stringbyappendingstring:str1]];
nslog(@
"count %lu at now",[set count]);
nslog(@
"%@",set);
nsmutabledictionary *dict = [[
nsmutabledictionary alloc] init];[dict setdictionary:@{@
1:@
1,@
2:@
"hh",@
"hi":@
1}];dict[@
11] = @
"what!?";
nslog(@
"%@ : %@",dict[@
1],dict);
nsmutablearray *ary = [
nsmutablearray arraywitharray:@[@
1,@
2,@
"hehe"]];
nslog(@
"%@",ary);ary[
2] = @
"smile!";
nslog(@
"%@ : %@",ary[
0],ary);
@try{
nslog(@
"value with bad index: %@",ary[
11]);
nslog(@
"never see me!");}
@catch(
nsexception *e){
nslog(@
"caught %@:%@",[e name],[e reason]);}
@finally{
nslog(@
"at last!!!");}}
return 0;
}
总结
以上是凯发k8官方网为你收集整理的objective-c 2.0的字面量literals的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发k8官方网网站内容还不错,欢迎将凯发k8官方网推荐给好友。