您的位置:首页 > 产品设计 > UI/UE

1) google questions and answers

2014-07-27 14:40 316 查看

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的变量的在两个不同的文件中都有定义.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: