objective-c 2.0的字面量Literals

简介:

obj-c 2.0增加了许多核心对象字面量的简单语法,向ruby学习吗?
直接上代码:

#import <Foundation/Foundation.h>

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);
        //NSLog(@"%@ %@",set[0],set[2]);
        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;
}
相关文章
|
安全 编译器 Swift
IOS开发基础知识: 对比 Swift 和 Objective-C 的优缺点。
IOS开发基础知识: 对比 Swift 和 Objective-C 的优缺点。
1647 2
|
开发工具 iOS开发 容器
【Azure Blob】关闭Blob 匿名访问,iOS Objective-C SDK连接Storage Account报错
iOS Objective-C 应用连接Azure Storage时,若不关闭账号的匿名访问,程序能正常运行。但关闭匿名访问后,上传到容器时会出现错误:“Public access is not permitted”。解决方法是将创建容器时的公共访问类型从`AZSContainerPublicAccessTypeContainer`改为`AZSContainerPublicAccessTypeOff`,以确保通过授权请求访问。
372 0
【Azure Blob】关闭Blob 匿名访问,iOS Objective-C SDK连接Storage Account报错
|
缓存 开发工具 iOS开发
优化iOS中Objective-C代码调起支付流程的速度
优化iOS中Objective-C代码调起支付流程的速度
441 2
|
安全 JavaScript 前端开发
IOS开发基础知识:介绍一下 Swift 和 Objective-C,它们之间有什么区别?
IOS开发基础知识:介绍一下 Swift 和 Objective-C,它们之间有什么区别?
1289 0
|
iOS开发 容器
iOS 代码规范格式 Objective-C(上)
iOS 代码规范格式 Objective-C
836 0
iOS 代码规范格式 Objective-C(上)
|
编译器 API iOS开发
iOS 代码规范格式 Objective-C(下)
iOS 代码规范格式 Objective-C(下)
471 0
|
机器学习/深度学习 API iOS开发
【IOS 开发】Objective-C Foundation 框架 -- 字符串 | 日期 | 对象复制 | NSArray | NSSet | NSDictionary | 谓词(一)
【IOS 开发】Objective-C Foundation 框架 -- 字符串 | 日期 | 对象复制 | NSArray | NSSet | NSDictionary | 谓词(一)
413 0
|
存储 自然语言处理 Java
【IOS 开发】Objective-C Foundation 框架 -- 字符串 | 日期 | 对象复制 | NSArray | NSSet | NSDictionary | 谓词(二)
【IOS 开发】Objective-C Foundation 框架 -- 字符串 | 日期 | 对象复制 | NSArray | NSSet | NSDictionary | 谓词(二)
512 0
|
存储 安全 C语言
【iOS 开发】Objective - C 面向对象 - 方法 | 成员变量 | 隐藏封装 | KVC | KVO | 初始化 | 多态(一)
【iOS 开发】Objective - C 面向对象 - 方法 | 成员变量 | 隐藏封装 | KVC | KVO | 初始化 | 多态(一)
469 0