탐색 데이터를 저장하기위한 plist 파일 ("myAwayList.plist")이 있습니다. 다음 나 ...Swift를 사용하여 plist 파일의 새 배열 데이터를 NSDictionary에 추가하는 방법
<dict>
<key>Locations</key>
<array>
<dict>
<key>Name</key>
<string>Sydney City Centre</string>
<key>Address</key>
<string>Centrepoint Tower</string>
<key>Lat</key>
<string>-33.870451</string>
<key>Lon</key>
<string>151.208771</string>
</dict> ...
I 성공적으로 로딩하고 다음으로 내부에 배열 된 데이터를 사용할 수있다 .. 주 사전에 배열
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) as NSArray
let documentsDirectory = paths.objectAtIndex(0)as NSString
let path = documentsDirectory.stringByAppendingPathComponent("myAwayList.plist")
let fileManager = NSFileManager.defaultManager()
// Check if file exists
if(!fileManager.fileExistsAtPath(path))
{
// If it doesn't, copy it from the default file in the Resources folder
let bundle = NSBundle.mainBundle().pathForResource("myAwayList", ofType: "plist")
fileManager.copyItemAtPath(bundle!, toPath: path, error:nil)
println("File did not exist! Default copied...")
}
let dict = NSDictionary(contentsOfFile: path)!
let mySavedLocations: AnyObject = dict.objectForKey("Locations")!
println("plist all: \(mySavedLocations)")
if let nsArray:NSArray = mySavedLocations as? NSArray{
for var loadCount = 0; loadCount < mySavedLocations.count; ++loadCount {
var locationDict:AnyObject = nsArray[loadCount] // loading array data at index
let arrayName = locationDict["Name"] as AnyObject? as String
let arrayAddress = locationDict["Address"] as AnyObject? as String
let arrayLat = locationDict["Lat"] as AnyObject? as String
let arrayLon = locationDict["Lon"] as AnyObject? as String
awaydatalist.append(AwayData(name:arrayName, address:arrayAddress, lat:arrayLat, lon:arrayLon)) // This is a list array used to display the loaded data on a ViewController
}
}
I를 문자열 변수의 사전 중첩 한 이제 다른 데이터 행과 함께 배열을 내부에 추가하고 plist 파일에 다시 쓰기를 원하지만이를 수행 할 방법을 찾을 수 없습니다. 제발 조언 해 줘? 여기에 크리스
배열 내부에 새 사전을 추가하고 plist.Right에서 데이터를 업데이트 하시겠습니까? –