2016-07-29 72 views
-3

在迅速這是從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 ..

+0

請提出這樣的問題顯然 – Spynet

回答

0

在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

相關問題