在 Swift 中,如何操作类型别名中的对象?

In Swift, how does one manipulate an object inside a typealias?

我有一个类型别名,我想在将它作为一个完成处理程序接收之后并在将它发送到另一个之前操作其中的一个对象。所以

typealias GalleryResponse = (gallery: MLGallery?, error: NSError?) -> ()

以及我想在类型别名上干预的函数:

func getGalleryForDiscover(onCompletion: galleryResponse) {

    let endpointURL = kGalleryURL + kMetaDataFilter + kLimitURL20

    /// Would like to do something here with the MLGallery object in the galleryResponse closure.   

    makeRequestToCurbsAt(endpointURL, completionHandler: onCompletion)
}

我如何到达那个 MLGallery 对象 - 操纵它 - 然后发送它?

您为 makeRequestToCurbsAt 提供它自己的完成处理程序,然后您 操纵传递给该处理程序的 MLGallary 实例,然后将其传递给原始处理程序。像这样:

func getGalleryForDiscover(onCompletion: galleryResponse) {
    let endpointURL = kGalleryURL + kMetaDataFilter + kLimitURL20

    makeRequestToCurbsAt(endpointURL, completionHandler: {
        (gallery: MLGallery?, error: NSError?) in
      // do something with gallery

      // invoke the original
      onCompletion (gallery: gallery, error: error)
    })
}

注意:真的,真的,你的 typealias 标识符应该大写为 GalleryResponse