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。
3. 在block中赋值出现错误 variable is not assignable (missing __block type specifier)
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的变量的在两个不同的文件中都有定义.
本文介绍了iOS开发中的几个实用技巧:如何遍历字典的key和value;解释了为何使用NSMutableArray的length会导致程序崩溃;探讨了在block中修改外部变量的方法;并解决了链接器错误的问题。

981

被折叠的 条评论
为什么被折叠?



