iOS/Objective-C 开发常用代码(1) 发表于 2012-12-16 | 分类于 ios | 判断iOS设备是否是iPad1#define IS_IPAD ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) iOS中URL编码12NSString* escapedURLString = [unescapedStringstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] 或123NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)yourtext, NULL,(CFStringRef)@”!*’();:@&=+$,/?%#[]“, kCFStringEncodingUTF8); iOS中不定参数(可变参数)的方法常见于NSArray初始化方法中,比如:12345@interface NSArray (NSArrayCreation)+ (id)arrayWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION;- (id)initWithObjects:(id)firstObj, ... NS_REQUIRES_NIL_TERMINATION;//...@end NS_REQUIRES_NIL_TERMINATION 是一个宏,用于编译时非nil结尾的检查。自定义不定参数的方法与C/C++一样,示例如下:12345678910111213141516- (id)initWithColumns: (NSString*)firstColumnName, ... { if (self = [self init]) { NSMutableArray* arrays = [NSMutableArray array]; va_list argList; if (firstColumnName) { [arrays addObject:firstColumnName]; va_start(argList, firstColumnName); id arg; while ((arg = va_arg(argList, id))) { [arrays addObject:arg]; } } self.columnNames = [NSArray arrayWithArray:arrays]; } return self;} 本文作者: Xinus 本文链接: http://xinus.wang/2012/12/code-fragments-oc-1/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!