我已經創建了英文和西班牙文單詞之間的小翻譯。如果用戶輸入「貓」,它將通過檢查索引號打印「el gato」。我想知道是否有任何方法可以從包含更多單詞的文件中讀取。Swift 2:從文件中讀取
文件1(英文) 文件2(西班牙語)
文件1將檢查 「你好」 文件2 「HOLA」 並打印正確的翻譯
import UIKit
class translateViewController: UIViewController {
@IBOutlet weak var translateTextField: UITextField!
@IBOutlet weak var translateButton: UIButton!
@IBOutlet weak var translateLabel: UILabel!
var englishArray: [String] = ["the cat", "the dog", "hello", ]
var spanishArray: [String] = ["el gato", "el perro", "hola"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func translateButtonTapped(sender: UIButton) {
let emptyString = self.translateTextField.text
if (emptyString!.isEmpty) {
print("please enter a word")
}
for transIndex in englishArray.indices {
if englishArray[transIndex] == emptyString!.lowercaseString {
translateLabel.text = "\(spanishArray[transIndex])"
print(transIndex)
return
}
}
}
}
怎麼樣的價值
el gato
對於那些沒有在數組列表但裏面本地化的話。字符串?它不會僅檢索數組中的單詞值。 @vadian – Miguel對不起,我不明白。 – vadian
說我有一個數組=「」貓「,」狗「],但在我的localizable.string裏面我有:」hello「=」hola「;當我在textField中輸入「hello」時,它不會檢索translateLabel.text中的值「hello」@vadian – Miguel