2015-04-22 82 views
-1

首先,我發現在StackOverflow上覆蓋這個問題的負載,但它全部是ObjectiveC而不是Swift。從Plist中提取映射註解swift

任何人都可以提供一個鏈接,或分享一些代碼來解釋如何從plist中提取註釋信息嗎?

我的plist是...

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<array> 
    <dict> 
     <key>name</key> 
     <string>London Eye</string> 
     <key>location</key> 
     <string>{51.503324,-0.119543}</string> 
    </dict> 
    <dict> 
     <key>name</key> 
     <string>Big Ben</string> 
     <key>location</key> 
     <string>{51.500729,-0.124625}</string> 
    </dict> 
</array> 
</plist> 

使用地圖套件,Xcode和斯威夫特。

到目前爲止,我的視圖控制器只包含的代碼,以獲得用戶位置,並允許用戶添加自定義註釋

很多感謝

回答

1

負載文件的plist

var dict: NSDictionary = NSDictionary() 

// load file to dict 

if let path = NSBundle.mainBundle().pathForResource("Name_file", ofType: "plist") { 

    dict = NSDictionary(contentsOfFile: path) 

} 

var array = dict["array"] as! NSMutableArray 

for item in array { 

    if let dic = item as? NSDictionary { 
     print(dic["key"] as! String) 
    } 

}