ios - '(_, _, _) -> Void' is not convertible to 'Result<Post> -> Void' -
in view controller have code:
newpost!.save({ (post, error) in //error here. if let anerror = error { print("error calling post on /posts") print(anerror) return } guard let post = post else { print("error calling post on /posts: result nil") return } // success! print(post.description()) print(post.title) })
i don't quite understand result<whatever>
syntax, result
should alamofire 2, post
class created, result<post> -> void
altogether mean , should change it?
update:
func save(completionhandler: (result<post>) -> void) { let fields: [string: anyobject]? = self.tojson() if fields == nil { print("error: error converting newpost fields json") return }
your completion handler definition , way have called different, try completion handler if want call way:
func save(completionhandler: (post:post?, error:string?) -> void) { let fields: [string: anyobject]? = self.tojson() if fields == nil { completionhandler(nil, "error converting newpost fields json") return } // rest of code, call completionhandler success }
for swift 2:
func save(completionhandler: (post:post?, error:string?) -> void) { guard let fields = self.tojson() else { completionhandler(nil, "error converting newpost fields json") return } // rest of code, call completionhandler success }
Comments
Post a Comment