Skip to content

Instantly share code, notes, and snippets.

@dealforest
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dealforest/edde2632c644c3dc9d04 to your computer and use it in GitHub Desktop.
Save dealforest/edde2632c644c3dc9d04 to your computer and use it in GitHub Desktop.
only Swfit 1.2
let request = GitHub.Endpoint.SearchRepositories(query: "APIKit", sort: .Stars)
GitHub.sendRequest(request)
.success { println($0) }
.failure { println($0) }
extension GitHub {
func sendRequest<T: APIKit.Request>(request: T) -> Task<Float, T.Response, NSError> {
return Task { progress, fulfill, reject, configure in
/*
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
を回避するために必要
*/
let fulfill = fulfill
let reject = reject
GitHub.sendRequest(request) { response in
switch response {
case .Success(let box):
fulfill(box.value)
case .Failure(let box):
reject(box.value)
}
}
}
}
}
@dealforest
Copy link
Author

これでもとおった

let a = GitHub.sendRequest(request) { response in
    switch response {
        case .Success(let box):
            fulfill(box.value)

        case .Failure(let box):
            reject(box.value)
    }
}

@dealforest
Copy link
Author

// NG
class A {
    func a() -> (String -> Void) {
        return { value in
            {
                println(value)
            }
        }
    }
}

// OK
class A {
    func a() -> (String -> Void) {
        return { value in
            let b = {
                println(value)
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment