这是从Swift到Objective C的正确转换吗?
问题描述:
在迅速这是从Swift到Objective C的正确转换吗?
在Objective C中
(![[tempPlays objectForKey:@"1"] integerValue]) // tempPlays is NSDictionary
帮助在此也?
斯威夫特
button0.setTitle(plays[0] == 0 ? "O": (plays[0] == 1 ? "X" : button0.titleLabel!.text!), forState: UIControlState.Normal)`
目标C
[_btn0 setTitle:([[playDictionary objectForKey:@"0"]integerValue] == 0 ? @"O" : ([[playDictionary objectForKey:@"0"]integerValue] == 1 ? @"X" : _btn0.titleLabel.text)) forState:UIControlStateNormal];`
新到iOS ..
答
在Objective-C
if (![tempPlays.allValues containsObject:@"1"]) {}
或
if (![tempPlays.allValues containsObject:@(1)]) {}
,让您更案例
NSString *titleBtn = _btn0.titleLabel.text;
if ([playDictionary[@"0"] integerValue] == 0) {
titleBtn = @"0";
}
else if ([playDictionary[@"1"] integerValue] == 1){
titleBtn = @"X";
}
[_btn0 setTitle:titleBtn forState:UIControlStateNormal];
+0
tempPlays是的NSDictionary .values不是它的财产! – iosLearner
+0
更新了答案,试试吧 – iSashok
+0
谢谢你的帮助:) – iosLearner
请提出这样的问题显然 – Spynet