1) google questions and answers

本文介绍了iOS开发中的几个实用技巧:如何遍历字典的key和value;解释了为何使用NSMutableArray的length会导致程序崩溃;探讨了在block中修改外部变量的方法;并解决了链接器错误的问题。

1. 如何同时iOS dictionary的key和value

http://stackoverflow.com/questions/1284429/is-there-a-way-to-iterate-over-a-dictionary

NSEnumerator *enumerator = [myDict keyEnumerator];
id key;
// extra parens to suppress warning about using = instead of ==
while((key = [enumerator nextObject]))
    NSLog(@"key=%@ value=%@", key, [myDict objectForKey:key]);

2. 为什么调用NSMutableArray length会crash

获取array中元素的个数请用count而不是length。

http://stackoverflow.com/questions/19856143/nsstring-under-arc-may-cause-nsarraym-length-unrecognized-selector-sent-to


3. 在block中赋值出现错误  variable is not assignable (missing __block type specifier)

http://stackoverflow.com/questions/7962721/how-to-assign-a-variable-inside-a-block-to-a-variable-outside-a-block

https://developer.apple.com/library/ios/documentation/cocoa/conceptual/Blocks/Articles/bxVariables.html

block本身默认不会改变global的外部变量,并且是使用的第一次当block定义的时候的变量,如果要改变请在变量定义之前加上__block

    int anInteger = 42;
 
   //  __block int anInteger = 42;   //只有这样菜可以在block中改变数值
    void (^testBlock)(void) = ^{  // 在第一次定义的时候已经将42作为一个const的数读进来
        NSLog(@"Integer is: %i", anInteger);
    };
    anInteger = 84;  // 不会改变block中的数值了
    testBlock();

4.  clang: error: linker command failed with exit code 1 (use -v to see invocation)

a按照提示把-v作为link的option加进去,然后重新编译,就会得到更详细的错误说明,原来是一个global的变量的在两个不同的文件中都有定义.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值