swift3

Receiving a notification without loading the view

孤者浪人 提交于 2019-12-12 03:32:47
问题 As I explained in this question, I'm trying to pass data from a UISwitch in a TableView to another ViewController. However, I want the data to be passed when the Settings View (which contains the UISwitch) is dismissed. Following the third step of this great answer, I'm using UserDefaults to pass the data and trying to use NotificationCenter to update the UserDefaults values when dismissing the Settings View. To update when user defaults values change, you could have your Settings controller

Swift Firebase Database Array of AutoID

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:27:54
问题 I would like to receive every graph item from all ChilDBYAutoID's into a double array. Also, Is there a better way to do this with a count so there is no auto ID? Such as example: 0 724 1 744 2 745 3 800 . . . My main goal is to upload many graph values, not just update one. And then retrieve the graph values into a Double Array. func uploadToFirebase(){ //Firebase Initialization var ref: FIRDatabaseReference! ref = FIRDatabase.database().reference() ref.child("general_room_index")

How to access `String`s at a given `Index` concisely?

不羁岁月 提交于 2019-12-12 03:22:46
问题 In Swift 3 SE-0065 changed the indexing model for Collection s, wherein responsibility for index traversal is moved from the index to the collection itself. For example, instead of writing i.successor() , onehas to write c.index(after: i) . What this means in terms of accessing String s at a certain index, is that instead of writing this: let aStringName = "Bar Baz" aStringName[aStringName.startIndex.advancedBy(3)] ...we now have to write this: aStringName[aStringName.index(aStringName

Swift 2 to Swift 3: Cannot convert value of type '(Data?, NSError?) -> Void' to to expected argument type 'GTMSessionFetcherCompletionHandler?'

孤人 提交于 2019-12-12 03:09:32
问题 I just updated a working Swift 2 to Swift 3 program, and I am getting the error, Cannot convert value of type '(Data?, NSError?) -> Void' to expected argument type 'GTMSessionFetcherCompletionHandler?' Here are the relevant details (I hope): let fetcher = GTMSessionFetcher(urlString:url) fetcher.authorizer = parentController.service.authorizer fetcher.beginFetch(completionHandler: handleDownload(studentNum)) ^^^^ causing the error The function for the completionHandler: func handleDownload(_

how to resolve “Type of expression in ambiguous without more context”? in swift 3.0

[亡魂溺海] 提交于 2019-12-12 03:08:49
问题 func setTimeLeft() { let timeNow = NSDate() { if timeEnd.compare(timeNow as Date) == ComparisonResult.orderedDescending { let calendar = NSCalendar.current let components = calendar.components([.day , .hour , .minute , .second] , fromDate: timeNow, toDate: timeEnd, options: []) var dayText = String(components.day) + "d " var hourText = String(components.hour) + "h " // Hide day and hour if they are zero if components.day <= 0 { dayText = "" if components.hour <= 0 { hourText = "" } }

Sinch Verification Swift 3

浪子不回头ぞ 提交于 2019-12-12 03:06:34
问题 I have been converting my code to swift 3. I have an issue with since verification: This is the code I have: verification.initiate { (success:Bool, error:Error?) -> Void in //handle outcome if (success){ print("successfully requested phone verification") //segue to next screen self.performSegue(withIdentifier: "xxx", sender: nil) } else { let alert = UIAlertController(title: "Alert", message: error?.localizedDescription, preferredStyle: .alert) alert.addAction(UIAlertAction(title: "Ok", style

Getting gestures to work with Subclassed UIButton

佐手、 提交于 2019-12-12 03:04:30
问题 I have a subclassed UIButton (DragButton) that I would like to be able to perform pan / pinch / rotate on. Instances of DragButton are created programmatically. There may be 1, there may be 20. All depends on the user. I am experiencing issues in getting these subclassed buttons to properly work with gestures. The main issue is none of the gestures trigger! Within DragButton class, inside the awakeFromNib instance method, the gestures don't work at all. Inside layoutSubviews, the panning

How to pass data between two ViewController using closure

浪尽此生 提交于 2019-12-12 02:43:47
问题 I want to know how to pass data using closure. I know that there are three types of data pass approaches: delegate Notification Center closure I want proper clarification of closure with an example. 回答1: Well passing data with blocks / closures is a good and reasonable approach and much better than notifications. Below is the same code for it. First ViewController (where you make object of Second ViewController) @IBAction func push(sender: UIButton) { let v2Obj = storyboard?

Core data issue Swift

半城伤御伤魂 提交于 2019-12-12 02:37:51
问题 Hello I am currently following a Swift tutorial which uses the old version of Swift and I am not able to follow this as I believe the syntax has changed in the newer version of Swift. class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. var appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate var context:NSManagedObjectContext = appDel.managedObjectContext

Kingfisher with Firebase storage slow to display images - swift 3

混江龙づ霸主 提交于 2019-12-12 02:36:22
问题 Im saving images from a picker up to firebase. Then I'm bringing them back down to my Tableview, but they update really slowly from kingfisher. even from the cache. If I reload the app offline, they still take time to appear Saving up to Firebase Storage func Save(image:UIImage, folderName:String, storeRefString:String, dbRefString:String) { let ref = FIRDatabase.database().reference(withPath: "Main") let database = FIRDatabase.database() let storage = FIRStorage.storage() let mainScreenItem