1

I'm trying to chain some promise on promise kit, I have syntax problem when the promise type is like this Promise<Location>, only when the promise has a type I get compiler error. I'm new on using promisekit

Swift.start(host,"","").then{ result -> Void in

    }.then{ obj -> Void in
        println(obj)
        Swift.getCurrent.then{ obj -> Void in
            let payload:Dictionary<String,AnyObject> = obj as! Dictionary<String,AnyObject>
            self.deviceUUID = payload["uuid"] as! String

        }
    }.then { obj -> Location in
        println(obj)
        Swift.getLocation("3333").then{ location in
            self.locationUUID = location.get("uuid")
        }
    }
Cesar Oyarzun
  • 169
  • 2
  • 8

2 Answers2

0

You don't need a return in your block:

.then { obj -> Location in
      Swift.getLocation("433434").then{ location in
          self.locationUUID = location.get("uuid")
      }
}
Patrick Tescher
  • 3,387
  • 1
  • 18
  • 31
0

There are a number of issues here.

  1. You are not chaining because you are not returning your promise.
  2. You are not returning in the 2nd closure, this is the compile error, the closure says it is returning a Location but the closure returns Void

.

Swift.start(host, "", "").then { result -> Void in

}.then { obj -> Promise<Something> in
    print(obj)

    // I changed the return of this closure, see above
    // we must return the promise or we are not chaining
    return Swift.getCurrent.then { obj -> Void in
        let payload: Dictionary<String, AnyObject> = obj as! Dictionary<String, AnyObject>
        self.deviceUUID = payload["uuid"] as! String

    }
}.then { obj -> Location in
    println(obj)

    // we promised a return value above, so we must return
    return Swift.getLocation("3333").then { location in
        self.locationUUID = location.get("uuid")
    }
}

However, looking at your code, it seems incorrect, is this actually what you are after?

firstly { _ -> Promise<[String: AnyObject]> in
    return Swift.getCurrent
}.then { payload -> Promise<Location> in
    self.deviceUUID = payload["uuid"] as! String
    return Swift.getLocation("3333")
}.then { location -> Void in
    self.locationUUID = location.get("uuid")
}
Zonily Jame
  • 5,053
  • 3
  • 30
  • 56
mxcl
  • 26,392
  • 12
  • 99
  • 98