[英]Swift returning a function with CloudKit data
我有一個CloudKit數據庫,其中包含這種格式的記錄...
我正在與一個示例Swift項目一起工作,該項目將Annotations放置在地圖上。 該項目將注釋數據存儲在僅在類文件中手動鍵入的函數數組中。 這是該文件中的代碼...
class POIService {
static let sharedInstance = POIService()
lazy var pointsOfInterest: Array<POI> = {
return [
POI(
title: "First interesting place.",
subtitle: "This place is great",
coordinate: CLLocationCoordinate2D(
latitude: 49.8519574378154,
longitude: -97.2117918551222
)
),
POI(
title: "Fifth interesting place.",
subtitle: "I don't know where I am...",
coordinate: CLLocationCoordinate2D(
latitude: 49.8141108489216,
longitude: -97.1298990909147
)
)
]
}()}
而是使用此數據來創建注釋,我希望能夠使用CloudKit數據以編程方式返回函數數組。 我可以毫無問題地獲取數據,但是對於編程有些陌生,我無法真正解決我將如何返回函數數組的問題。 我試圖創建一個返回另一個函數的函數,以便能夠創建數組,但是最終我迷路了。
這是github上項目的鏈接(我不是作者)... https://github.com/Winnipeg-iOS-Developers/InterestingPoint
我只是想從我的CloudKit數據庫返回地圖上的點,而不是使用它們的樣本數據。
任何幫助將不勝感激。 我真的在嘗試從該項目中學習盡可能多的知識,但這使我完全陷入僵局。
謝謝
我不確定是否能得到你。 你是說像
func someFunc(a:String, b:Bool)->String {
return "Test"
}
var arrayOfFunctions : [(String, Bool)->String] = [
{(param1 : String, param2: Bool) -> String in
"Hello"
},
{(param1 : String, param2: Bool) -> String in
"Bye"
},
someFunc
]
函數類型的語法為(param1:Type1,...,paramN:TypeN)->ReturnType
成員只是函數的閉包或引用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.