1
LocalsInformationクラスのローカル辞書に値を追加しようとしていますが、データが永続しません。 print(localInformation)にブレークポイントを設定して、新しい値が辞書に追加されていることがわかりましたが、アプリケーションをリロードするとその値は保持されません。私は実際の価値ではなく、地元の辞書のコピーを変更するだけかもしれないと信じています。ディクショナリへの値の追加が持続しない
class LocalsInformation{
var locals: [String: Dictionary<String, String>] = ["Jerry":["City":Destination.Seattle.rawValue,"Preference": TravellingPreference.Adventurer.rawValue, "Gender": Gender.Male.rawValue],"Beth":["City":Destination.Seattle.rawValue,"Preference":TravellingPreference.Foodie.rawValue, "Gender": Gender.Female.rawValue]}
let localInput = [[Destination.Austin.rawValue, Destination.Boston.rawValue, Destination.Chicago.rawValue, Destination.NewYork.rawValue, Destination.SanFrancisco.rawValue, Destination.Seattle.rawValue],[TravellingPreference.Adventurer.rawValue, TravellingPreference.ArtDesignLover.rawValue, TravellingPreference.CulturalExplorer.rawValue, TravellingPreference.Foodie.rawValue, TravellingPreference.HistoryBuff.rawValue, TravellingPreference.NightOwl.rawValue]]
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
let citySelected = localInput[0][pickerView.selectedRowInComponent(0)]
let preferenceSelected = localInput[1][pickerView.selectedRowInComponent(1)]
if let name = nameTextField.text{
var localInformation = LocalsInformation().locals
localInformation[name] = [
"City": citySelected,
"Preference": preferenceSelected,
"Gender": "Female"
]
LocalsInformation().locals[name] = localInformation[name]
print(localInformation)
}
}
を使用することができますどのようにプログラム、アプリ:辞書から使いやすい一つがJSONでありますなどは、プログラミング言語を記述するときに一般的に動作します。あなたの情報は、あなたのアプリが動いているときだけメモリに残っています。データを永続化するには、NSUserDefaults、CoreDataなどの別の方法を見つける必要があります。Googleの 'persist data ios'にあります。 –