ios高级进阶技能

有一种方便的方式来访问插入到 storyboard 容器视图的子控制器:

Objective-C
// 1. A property has the same name as a segue identifier in XIB
@property (nonatomic) ChildViewController1 *childController1;
@property (nonatomic) ChildViewController2 *childController2;

// #pragma mark - UIViewController

- (void)prepareForSegue:(UIStoryboardSegue *)segue
                 sender:(id)sender
{
    [super prepareForSegue:segue sender:sender];

    // 2. All known destination controllers assigned to properties
    if ([self respondsToSelector:NSSelectorFromString(segue.identifier)]) {
        [self setValue:segue.destinationViewController forKey:segue.identifier];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // 3. Controllers already available bc viewDidLoad is called after prepareForSegue
    self.childController1.view.backgroundColor = [UIColor redColor];
    self.childController2.view.backgroundColor = [UIColor blueColor];
}

NSDateFormatter +dateFormatFromTemplate:options:locale:

友情提示:如果你在使用 NSDateFormatter -setDateFormat: 而不同时使用NSDateFormatter +dateFormatFromTemplate:options:locale: 那么你很可能做错了。

文档是这样的:

Objective-C
+ (NSString *)dateFormatFromTemplate:(NSString *)template
                             options:(NSUInteger)opts
                              locale:(NSLocale *)locale

不同的语言对时间要素有不同的规范。你用这个方法来得到某个特定语言(通常使用当前的语言 - 参看 currentLocale)给定的时间要素的正确字符串格式。


NSBundle -preferredLocalizations

有时候,你需要知道你的应用程序在什么语言环境下运行。通常,人们会用 NSLocale +preferredLanguages。不幸的是这除了告诉你应用程序实际上显示的语言之外一无所知。它只是给你 iOS 中 "Settings → General → Language & Region → Preferred Language" 或是 OS X 里 "System Preferences → Language & Region → Preferred Languages" 同样的有序列表。

想象一下如果首选语言顺序是 {英语, 法语} 但是你的应用程序只支持德语。调用[NSLocale preferredLanguages] firstObject] 会返回英语而不是你想要的德语。

得到应用程序使用的准确语言环境的正确方式是使用 [[NSBundle mainBundle] preferredLocalizations]

文档是这么说的:

一个 NSString 对象的数组包含了 bundle 里的区域语言 ID。这些字符串是按用户系统设置和可用本地化来排序的。

NSBundle.h 里的注释说:

这个 bundle 本地化的子集,会对这个进程的当前执行环境的优先顺序上重新排序;主 bundle 的首选本地化显示了用户是最有可能在 UI 看到的语言(文本)

你大概还需要使用 NSLocale +canonicalLanguageIdentifierFromString: 来确保规范的语言标识。

阻止 dylib 钩子

来自 Sam Marshall 的这一招使黑客的生活更艰难:> >

把这一行加到你的 "Other Linker Flags" 里:

-Wl,-sectcreate,__RESTRICT,__restrict,/dev/null

揭露 CocoaPods!

有一个快速方法来检查(闭源)应用程序使用的所有源:

$ class-dump -C Pods_ /Applications/Squire.app | grep -o "Pods_\w+"

不需要重新编译的重新运行

如果你一遍又一遍的调试同样的问题,你可以不重新编译就运行你的应用程序: "Product > Perform Action > Run without Building" (⌘⌃R)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值