iOS开发Tips3

  • SEL
  • 输出函数
  • nil,Nil,Null,NSNull,null区别
  • 检测系统版
  • iOS中使用blend改变图片颜色

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

SEL

Objective-C在编译的时候,会根据方法的名字(包括参数序列),生成一个用 来区分这个方法的唯一的一个ID,这个ID就是SEL类型的。我们需要注意的是,只要方法的名字(包括参数序列)相同,那么它们的ID都是相同的。就是 说,不管是超类还是子类,不管是有没有超类和子类的关系,只要名字相同那么ID就是一样的。

       我们可以方便的通过方法的名字,获取到方法的ID也就是我们所说的SEL,反之亦然。具体的使用方法如下: 

SEL 变量名 = @selector(方法名字);     
SEL 变量名 = NSSelectorFromString(方法名字的字符串);     
NSString *变量名 = NSStringFromSelector(SEL参数);  
这样的机制大大的增加了我们的程序的灵活性,我们可以通过给一个方法传递SEL参数,让这个方法动态的执行某一个方法;我们也可以通过配置文件指定需要执行的方法,程序读取配置文件之后把方法的字符串翻译成为SEL变量然后给相应的对象发送这个消息。 

  从效率的角度上来说,执行的时候不是通过方法名字而是方法ID也就是一个整数来查找方法,由于整数的查找和匹配比字符串要快得多,所以这样可以在某种程度上提高执行的效率。


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

输出函数

根据不同的输出格式输出不同的值 (%d :整形 ,%@:对象<发送description消息>,%s:字符串)

     NSlog(@“The result is %d”,intNum); 

     

     CF代表Core Foundation (Cocoa)

     CFShow发送description给它显示的对象,CFShow打印的信息不会显示时间戳,NSLog会显示,同时CFShow不需要格式字符串,它只能用于对象

     CFShow(obj);

转自:http://blog.csdn.net/tangren03/article/details/7741853

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

nil,Nil,Null,NSNull,null区别

nil: A null pointer to an Objective-C object. ( #define nil((id)0) )
nil 是一个对象值。

Nil: A null pointer to an Objective-C class.

NULL: A null pointer to anythingelse. ( #define NULL ((void*)0) )
NULL是一个通用指针(泛型指针)。

NSNull: A class defines a singletonobject used to represent nullvalues in collection objects (which don't allow nilvalues).
[NSNull null]: The singleton instance of NSNull.
[NSNull null]是一个对象,他用在不能使用nil的场合。
因为在NSArray和NSDictionary中nil中有特殊的含义(表示列表结束),所以不能在集合中放入nil值。如要确实需要存储一个表示“什么都没有”的值,可以使用NSNull类。NSNull只有一个方法:
+ (NSNull *) null;

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

检测系统版

   

 float version = [[[UIDevice currentDevice] systemVersion] floatValue];

下面是ios内其他相关信息的判断方法:

获取进程信息和设备信息(包括设备类型,序列号,ios版本等)
[[NSProcessInfo processInfo] globallyUniqueString],
[[NSProcessInfo processInfo] hostName],
[[NSProcessInfo processInfo] operatingSystemName],
[[NSProcessInfo processInfo] operatingSystemVersionString],
[[NSProcessInfo processInfo] physicalMemory],
[[NSProcessInfo processInfo] processName]);
——————————————————————————————
[UIDevice currentDevice].uniqueIdentifier,
[UIDevice currentDevice].name,
[UIDevice currentDevice].systemName,
[UIDevice currentDevice].systemVersion,
[UIDevice currentDevice].model,
[UIDevice currentDevice].localizedModel,
[UIDevice currentDevice].batteryLevel
___________________________________________________
NSLog([[UIDevice currentDevice] name]); // Name of the phone as named by user
NSLog([[UIDevice currentDevice] uniqueIdentifier]); // A GUID like string
NSLog([[UIDevice currentDevice] systemName]); // "iPhone OS"
NSLog([[UIDevice currentDevice] systemVersion]); // "2.2.1"
NSLog([[UIDevice currentDevice] model]); // "iPhone" on both devices
NSLog([[UIDevice currentDevice] localizedModel]); // "iPhone" on both devices

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

iOS中使用blend改变图片颜色

http://onevcat.com/2013/04/using-blending-in-ios/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值