我試圖把這種Objective-C代碼爲斯威夫特之後訪問:初始化變量,並在改變其值的for循環
- (void) performActivity{
NSMutableString *reversedStrings = [[NSMutableString alloc] init];
for (NSString *string in self.activityItems){
[reversedStrings appendString:[self reverseOfString:string]];
[reversedStrings appendString:@"\n"];
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Reversed"
message:reversedStrings
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
我的銀行代碼是:
override func performActivity() {
var reversedStrings = String()
for string in activityItems{
reversedStrings += reverseOfString(string)
reversedStrings += "\n"
}
var alert = UIAlertView(title: "Reversed",
message: reversedStrings,
delegate: self,
cancelButtonTitle: "Cancel",
otherButtonTitles: "Ok")
alert.show()
}
但我的警報中的消息仍然是空字符串。如何訪問for循環的結果reverseStrings?在此先感謝您的答案。
我相信'reverseOfString'是您開發一個類的方法。可能錯誤在那裏 - 你可以發佈它的實現嗎? – Antonio 2014-08-30 06:02:51