iOS 开发中的一些注意点(安全、当前语言、时间格式化)
2016-03-24 23:32
399 查看
1.重复运行项目,不重复构建项目(来自Heath Borders)
假如你一直在不停地调试同一个问题,你可以在不重复构建的情况下运行你的APP,这样:“Product>Perform Action>Run without Building”
2.禁用dylib钩子(来自Sam Marshall)
在你的“Other Linker Flags”里加上下面这行:
3.NSBundle -preferredLocalizations
某些时候,你需要知道APP当前使用的是什么语言。eg:优先语言列表中只有{英语,法语},但你的APP仅使用德语;调用[[NSLocal preferredLanguages] firstObject]返回给你的是英语,而不是德语。正确的方法是用[[NSBundle mainBundle] preferredLocalizations]方法。
4.NSDateFormatter +dateFormatFromTemplate:options:locale:
友情提示:假如你调用[NSDateFormatter setDateFormat],而没有调用[NSDateFormatter dateFormatFromTemplate:options:local:],n那么很可能出错。
不同地区有不同的日期格式。使用这个方法的目的:得到指定地区指定日期字段的一个合适的格式(通常你可以通过currentLocal查看当前所属地区)
下面这个例子给我们表现了英式英语和美式英语不同的日期格式:
假如你一直在不停地调试同一个问题,你可以在不重复构建的情况下运行你的APP,这样:“Product>Perform Action>Run without Building”
2.禁用dylib钩子(来自Sam Marshall)
在你的“Other Linker Flags”里加上下面这行:
-Wl,-sectcreate,__RESTRICT,__restrict,/dev/null
3.NSBundle -preferredLocalizations
某些时候,你需要知道APP当前使用的是什么语言。eg:优先语言列表中只有{英语,法语},但你的APP仅使用德语;调用[[NSLocal preferredLanguages] firstObject]返回给你的是英语,而不是德语。正确的方法是用[[NSBundle mainBundle] preferredLocalizations]方法。
4.NSDateFormatter +dateFormatFromTemplate:options:locale:
友情提示:假如你调用[NSDateFormatter setDateFormat],而没有调用[NSDateFormatter dateFormatFromTemplate:options:local:],n那么很可能出错。
+ (NSString *)dateFormatFromTemplate:(NSString *)template options:(NSUInteger)opts locale:(NSLocale *)locale
不同地区有不同的日期格式。使用这个方法的目的:得到指定地区指定日期字段的一个合适的格式(通常你可以通过currentLocal查看当前所属地区)
下面这个例子给我们表现了英式英语和美式英语不同的日期格式:
NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; NSLocale *gbLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_GB"]; NSString *dateFormat; NSString *dateComponents = @"yMMMMd"; dateFormat = [NSDateFormatter dateFormatFromTemplate:dateComponents options:0 locale:usLocale]; NSLog(@"Date format for %@: %@", [usLocale displayNameForKey:NSLocaleIdentifier value:[usLocale localeIdentifier]], dateFormat); dateFormat = [NSDateFormatter dateFormatFromTemplate:dateComponents options:0 locale:gbLocale]; NSLog(@"Date format for %@: %@", [gbLocale displayNameForKey:NSLocaleIdentifier value:[gbLocale localeIdentifier]], dateFormat); // Output: // Date format for English (United States): MMMM d, y // Date format for English (United Kingdom): d MMMM y
相关文章推荐
- iOS 25个性能优化/内存优化常用方法
- iOS 正则表达式的使用 —— HERO博客
- IOS学习 collectionView 的创建
- Upgrading Nagios Core 4. "How to Upgrade Nagios Core 4."
- iOS之即时通信 XMPP
- iOS 事件处理机制与图像渲染过程
- Nagios Fusion-FAQs
- OC阅读笔记一:尽量使用不可变对象
- 2016-03-24 iOS播放沙盒视频
- iOS高级控件之ScrollView分析(一)
- IOS中登陆界面如何跳转到含tabbar的界面
- iOS奇葩BUG:蓝色小圆点
- iOS奇葩BUG:蓝色小圆点
- iOS中delegate代理对象使用weak和assign哪个
- iOS开发中代码块的使用
- IOS开发之GitHub优秀源码分享/优秀第三方转载
- iOS-滤镜
- IOS 数组/字典转json串
- 十大ios开发者喜爱的开源库
- 十大ios开发者喜爱的开源库