zoukankan      html  css  js  c++  java
  • 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
    vs2010 VS2008 VS2005 快捷键大全
    css 常用标签
    JS Array数组操作
    CSS属性
    jquery 选择器大全
    @fontface
    以前写过的ajax基础案例(王欢huanhuan)
    Jquery操作下拉框(DropDownList)的取值赋值实现代码(王欢)
  • 原文地址:https://www.cnblogs.com/fuunnyy/p/5317797.html
Copyright © 2011-2022 走看看