completionhandler

How does a completion handler work on iOS?

僤鯓⒐⒋嵵緔 提交于 2019-12-18 10:41:35
问题 Im trying to understand completion handlers & blocks. I believe you can use blocks for many deep programming things without completion handlers, but I think i understand that completion handlers are based on blocks. (So basically completion handlers need blocks but not the other way around). So I saw this code on the internet about the old twitter framework: [twitterFeed performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { if (!error) { self

UIActivityViewController completionHandler how to check if activity send or not successfully?

耗尽温柔 提交于 2019-12-18 05:18:22
问题 I want to send one string via airdrop, I want to call one function when the String is received on other device successfully. I had implemented it through UIActivityViewController and I check it via completionHandler. Here is my scenario : Device A ->send a string To Device B If Device B receive have two option -> Accept or Decline I want to call one function on Device A when Device B will receive or Decline that message. Below is my implementation: UIActivityViewController

Wait for Firebase to load before returning from a function

假如想象 提交于 2019-12-16 20:06:29
问题 I have a simple function loading data from Firebase. func loadFromFireBase() -> Array<Song>? { var songArray:Array<Song> = [] ref.observe(.value, with: { snapshot in //Load songArray }) if songArray.isEmpty { return nil } return songArray } Currently this function returns nil always, even though there is data to load. It does this because it doesn't ever get to the perform the completion block where it loads the array before the function returns. I'm looking for a way to make the function

Returning method object from inside block

寵の児 提交于 2019-12-16 20:05:35
问题 I am wondering how to do the following correctly: I have a method that is to return an NSData object. It gets the NSData object from a UIDocument . The NSData object can get large, so I want to make sure it is fully loaded before the response starts. I would therefore like to return the value of the method from within the block itself. So something like this: - (NSData*)getMyData { MyUIDocument *doc = [[MyUIDocument alloc] initWithFileURL:fileURL]; [doc openWithCompletionHandler:^(BOOL

How to return values from Haneke's async fetch method

為{幸葍}努か 提交于 2019-12-14 02:44:42
问题 I'm trying to parse some data that I cached using Haneke Swift . I've cached the data and have written the parser to accomplish this. This parser is in a separate class called AssembleCalendar() . Using Haneke's example code for fetching, I've tried with complete and utter failure to actually return a value from the closure. My attempt func getScheduledItems() -> [ScheduledItem] { var scheduledItem = [ScheduledItem]() // initialize array let cache = Shared.dataCache cache.fetch(key:

Returning method object from inside block

戏子无情 提交于 2019-12-13 07:23:48
问题 I am wondering how to do the following correctly: I have a method that is to return an NSData object. It gets the NSData object from a UIDocument . The NSData object can get large, so I want to make sure it is fully loaded before the response starts. I would therefore like to return the value of the method from within the block itself. So something like this: - (NSData*)getMyData { MyUIDocument *doc = [[MyUIDocument alloc] initWithFileURL:fileURL]; [doc openWithCompletionHandler:^(BOOL

Creating reusable View in Swift and adding a completion handler

北城以北 提交于 2019-12-13 04:33:35
问题 I created a sliderView, and added a UIPanGesture and I created a seperate UIView to handle this slider. I want to be able to call this SliderView in different ViewControllers where I need it but when I try to run my code IT crashed.I also would want to pass a completion handler to handle events in the ViewCOntrollers where I would be needing it. I am trying to follow the DRY process by creating one UIView and using it in mutiple screen. Below is my code so far class TripView: UIView { var

In SceneKit SCNAction hangs when called from completion handler of RunAction

纵然是瞬间 提交于 2019-12-13 04:27:38
问题 Calling an SCNAction from the completion handler of RunAction seems to hang SceneKit. A touch event or rotating the device seems to unblock the hang. To reproduce: 1) Take the default SceneKit project you get on startup with the rotating spaceship. 2) Replace the animation code: ship.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 2, 0, 1))); with: ship.RunAction(SCNAction.RotateBy(0, 2, 0, durationInSeconds: 3.0f), delegate { Console.WriteLine("DONE ROTATE"); ship.RunAction

How to use completion handler correctly [duplicate]

百般思念 提交于 2019-12-12 03:56:13
问题 This question already has answers here : NSURLConnection sendAsynchronousRequest can't get variable out of closure (1 answer) How do I return the response from an asynchronous call? (36 answers) Closed 3 years ago . I understand how completion handlers work, but im a bit confused on the syntax. Below is a function that, given a username, calls a parse query to find out the corresponding userId. The query ends after the function is returned (so it returns nil), which is why we need the

NSURLSession completion handler very slow

…衆ロ難τιáo~ 提交于 2019-12-12 02:59:29
问题 When I run the following code, I can print a response almost immediately, however, it can take ten seconds or more to appear in my view. It seems like most similar problems are caused by the session and the handler being on different threads. But why does it work eventually? Very confused... func downloadDetails(completed: DownloadComplete) { let url = NSURL(string: _detailsURL)! let session = NSURLSession.sharedSession() let task = session.dataTaskWithURL(url) { (data, response, error) ->