繁体   English   中英

Swift使用CloudKit数据返回函数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM