ここでは、アノテーションのデータがオブジェクトの配列に格納されておらず、サンプルコードが100個あると仮定しています。
情報が静的な場合は、情報をプロパティリスト(plist)に含めることができます。あなたは、その後のplistをロードし、マップに自分の注釈を追加するための場所の配列を反復処理することができます
<dict>
<key>Locations</key>
<array>
<dict>
<key>Title</key>
<string>First annotation</string>
... more information here
</dict>
<dict>
<key>Title</key>
<string>Second annotation</string>
... more information here
</dict>
</array>
</dict>
</plist>
:
あなたのplistは次のようになります。このようなもの:
func addAnnotations()
{
// load your plist
if let path = NSBundle.mainBundle().pathForResource("StaticInformation", ofType: "plist") {
if let dict = NSDictionary(contentsOfFile: path) as? Dictionary<String, AnyObject> {
// get your static locations information as an array
if let locations = dict["Locations"] as? Array<Dictionary<String, AnyObject>> {
// iterate your locations
for (index, location) in locations.enumerate() {
let title = location["Title"] as? String
// obtain the information needed from the location dict
// create your annotation
let first = Artwork(title: title,
locationName: ...,
discipline: ...,
coordinate: ...)
map.addAnnotation(first)
}
}
}
}
}
コードはテストされていません。申し訳ありません。しかし、うまくいけば、あなたはそのアイデアを得ます
データ配列はどのように見えますか?投稿できる場合は、適切なコードで回答することができます。 –