你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS編程技術 >> iOS 開發中的一些注意點(安全、當前語言、時間格式化)

iOS 開發中的一些注意點(安全、當前語言、時間格式化)

編輯:IOS編程技術

1.重復運行項目,不重復構建項目(來自Heath Borders)

假如你一直在不停地調試同一個問題,你可以在不重復構建的情況下運行你的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
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved