2016-12-05 6 views
-3

私はマップ上の建物を選択してリストに保存できるアプリケーションを作成しています。すべては問題ありませんが、アプリの終了後にユーザーの選択を保存する必要があります。iOSアプリの永続的な保存方法

func action(_ gestureRecognizer:UIGestureRecognizer) { // GESTURE RECOGNIZER FUNCTION 

    if gestureRecognizer.state == UIGestureRecognizerState.began { 

     let touchPoint = gestureRecognizer.location(in: self.map) 

     let newCoordinate = self.map.convert(touchPoint, toCoordinateFrom: self.map) 

     let location = CLLocation(latitude: newCoordinate.latitude, longitude: newCoordinate.longitude) 

     CLGeocoder().reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in 


      var title = "" 

      if (error == nil) { 

       if let p = placemarks?[0] { 


        var subThoroughfare:String = "" 
        var thoroughfare:String = "" 

        if p.subThoroughfare != nil { 

         subThoroughfare = p.subThoroughfare! 

        } 

        if p.thoroughfare != nil { 

         thoroughfare = p.thoroughfare! 

        } 
+1

ようこそ!あなたは[ツアー](http://stackoverflow.com/tour)に参加し、[質問する方法](http://stackoverflow.com/help/how-to-ask)を学んで[最小限、Complete、and Verifiable example](http://stackoverflow.com/help/mcve)を参照してください。そうすれば、私たちがあなたを助けやすくなります。 – Starlord

答えて

0

建物IDを配列に保存し、その配列をUserDefaultsに保存することができます。

UserDefaults.standard.set(value: buildingIds, forKey: "myBuildingIds") 

あなたがアプリを開くと、単純に尋ねる:

if let myBuildingArrays = UserDefaults.standard.value(forKey: "myBuildingIds"){ 
//And here you iterate each value of the array to load them into your list. 
} 

詳細情報:スタックオーバーフローにhttps://developer.apple.com/reference/foundation/userdefaults

関連する問題