mxcl / PromiseKit

Promises for Swift & ObjC.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hi, i want use anypromise in swift, but get a error.

a603938361 opened this issue · comments

PromiseKit version 6.5.3
Pod version 1.11.3

oc code
.m
- (AnyPromise * _Nonnull)fetchThings { return [AnyPromise promiseWithValue:@[@"a", @"b", @"c"]]; }

and swift code
let wxModule = WxShareModule() wxModule.fetchThings().map { $0 as! [String] }.done { }

and get this error
image

please help me, thanks

Because the network framework returns the data by OC, the return value is anypromise, I want to use promise in swift, But I don't know how to convert。 Please help me, thank you。

This is fine, chances are the error is hiding. Separate out the steps to see what the error actually is:

let wxModule = WxShareModule()
let a = wxModule.fetchThings()
let b = a.map{ $0 as! [String] }
let c = b.done { }

hi get this error
image

let a type is AnyPromise
map func Promise

I suggest you read our tests and use an example from there: https://github.com/mxcl/PromiseKit/blob/v6/Tests/Bridging/BridgingTests.swift