这是从Swift到Objective C的正确转换吗?

时间:2016-07-29 09:42:49

标签: ios objective-c swift

在swift中

!tempPlays.values.contains(1)

目标C

(![[tempPlays objectForKey:@"1"] integerValue]) // tempPlays is NSDictionary

也可以帮忙吗?

IN SWIFT

 button0.setTitle(plays[0] == 0 ? "O": (plays[0] == 1 ? "X" : button0.titleLabel!.text!), forState: UIControlState.Normal)`

IN OBJECTIVE C

 [_btn0 setTitle:([[playDictionary objectForKey:@"0"]integerValue] == 0 ? @"O" : ([[playDictionary objectForKey:@"0"]integerValue] == 1 ? @"X" : _btn0.titleLabel.text)) forState:UIControlStateNormal];`

iOS新手..

1 个答案:

答案 0 :(得分: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];