Skip to content

Instantly share code, notes, and snippets.

@frootloops
Last active December 30, 2017 09:03
Show Gist options
  • Save frootloops/1250835b3666170a9410b3118d8958a4 to your computer and use it in GitHub Desktop.
Save frootloops/1250835b3666170a9410b3118d8958a4 to your computer and use it in GitHub Desktop.
func fetchUserId(completion: @escaping (Int?, Error?) -> Void) {
let request = URLRequest(url: URL(string: "http://facebook.com/me"))
URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
completion(Int(data), nil)
} else if error = error {
completion(nil, error)
}
}.resume()
}
fetchUserId { userId, error in
print(userId, error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment