completionhandler

Set address string with reverseGeocodeLocation: and return from method

泪湿孤枕 提交于 2019-11-28 02:17:09
问题 I'm try to localize a start and end point to an address string, so that I can store it into NSUserDefaults . The problem is that the method continues executing and does not set my variable. NSLog(@"Begin"); __block NSString *returnAddress = @""; [self.geoCoder reverseGeocodeLocation:self.locManager.location completionHandler:^(NSArray *placemarks, NSError *error) { if(error){ NSLog(@"%@", [error localizedDescription]); } CLPlacemark *placemark = [placemarks lastObject]; startAddressString =

Reloading a UICollectionView using reloadData method returns immediately before reloading data

爱⌒轻易说出口 提交于 2019-11-27 19:15:48
问题 I need to know when reloading a UICollectionView has completed in order to configure cells afterwards (because I am not the data source for the cells - other wise would have done it already...) I've tried code such as [self.collectionView reloadData]; [self configure cells]; // BOOM! cells are nil I've also tried using [self.collectionView performBatchUpdates:^{ [self.collectionView reloadData]; } completion:^(BOOL finished) { // notify that completed and do the configuration now }]; but when

How can I return an object that I create in my data service class through Firebase?

一笑奈何 提交于 2019-11-27 09:51:36
I am trying to adhere to MVC practices and keep all the network code inside the data service class that I am using in my app. On one screen I have the user's name and username that needs to be displayed. When updating this, I am calling this function: func grabUserData() -> User { REF_USERS.child(getCurrentUID()).observeSingleEvent(of: .value) { (snapshot) in if let userDict = snapshot.value as? Dictionary<String, String> { let user = User( first: userDict["firstName"]!, last: userDict["lastName"]!, username: userDict["username"]! ) return user } } } But I am getting an error trying to return

Difference Between Completion Handler and Blocks : [iOS]

天涯浪子 提交于 2019-11-27 01:31:35
问题 I am messed with both completion handler and blocks while I am using them in Swift and Objective-C . And when I am searching blocks in Swift on google it is showing result for completion handler! Can somebody tell me what is the difference between completion handler and blocks with respect to Swift and Objective-C ? 回答1: Here you can easily differentiate between blocks and completion handlers in fact both are blocks see detail below. Blocks: Blocks are a language-level feature added to C,

How can I return an object that I create in my data service class through Firebase?

谁说胖子不能爱 提交于 2019-11-26 14:55:10
问题 I am trying to adhere to MVC practices and keep all the network code inside the data service class that I am using in my app. On one screen I have the user's name and username that needs to be displayed. When updating this, I am calling this function: func grabUserData() -> User { REF_USERS.child(getCurrentUID()).observeSingleEvent(of: .value) { (snapshot) in if let userDict = snapshot.value as? Dictionary<String, String> { let user = User( first: userDict["firstName"]!, last: userDict[

Xcode 8 :function types cannot have argument label breaking my build

泄露秘密 提交于 2019-11-26 09:38:38
问题 It seems that for some reason Swift have chosen to make coding in it less readable by forcing users to remove completion handler parameter labels. I have read the Swift discussion and still think it\'s a mistake. At least they could have made it optional. When building using Xcode 8 - is there a way to force the compiler to use Swift 2.3 so I don\'t get these errors anymore? I have updated the option to use legacy Swift (under build settings) but I still seem to get this error: Function types

How could I create a function with a completion handler in Swift?

这一生的挚爱 提交于 2019-11-26 02:41:25
问题 I was just curious as to how I would approach this. If I had a function, and I wanted something to happen when it was fully executed, how would I add this into the function? Thanks 回答1: Say you have a download function to download a file from network, and want to be notified when download task has finished. typealias CompletionHandler = (success:Bool) -> Void func downloadFileFromURL(url: NSURL,completionHandler: CompletionHandler) { // download code. let flag = true // true if download