[Solved] How to hide show UIButton text not button in IOS Swift [closed]

As you are saying that you can’t nil the button’s text, you should do this, You can implement this Bool extension also, extension Bool { mutating func toggle() { self = !self } } @IBAction func myButton(_ sender: UIButton) { sender.titleLabel?.isHidden.toggle() } this will show and hide your Button’s titleLabel text. UPDATE @IBAction func btnTapped(_ … Read more

[Solved] How would you handle getting new data from the server? [closed]

You might feel surprised to have received so many vote-downs. The reason is that you have not provided any information concerning what you have tried to solve the problem. Since you have not provided any specifics either, I’ll assume you want some basically structured data (e.g. JSON) to send/retrieve from server. Following code will let … Read more

[Solved] Getting the first date from what a user has selected

First you need to create an enumeration for the weekdays: extension Date { enum Weekday: Int { case sunday = 1, monday, tuesday, wednesday, thursday, friday, saturday } } Second create an extension to return the next weekday desired: extension Date { var weekday: Int { return Calendar.current.component(.weekday, from: self) } func following(_ weekday: Weekday) … Read more

[Solved] Return struct after parsing json in Swift

I found the solution. You have to add a closure and then use it when calling the function. func getData(symbol: String, completion: @escaping (Stock) -> Void) { let apiURL = “https://cloud.iexapis.com/stable/stock/\(symbol)/quote?token=\(secretToken)” let url = URL(string: apiURL)! URLSession.shared.dataTask(with: url) { (data, response, err) in guard let data = data else { return } do { let … Read more

[Solved] Second If statement gets called before first statement finished in one function

Asynchronous methods! You have to wait for the completion before you move on to the next step. Put the second block within the first completion handler – like this func pictureFromFirebase(loginMethod: Int) { if loginMethod == 0 //FB { var profilePic = FBSDKGraphRequest(graphPath: “me/picture”, parameters: [“height”:300, “width”:300, “redirect”:false], httpMethod: “GET”) let profilePicRef = storageRef.child((user?.uid)!+”/profile_pic.jpg”) profilePicRef.data(withMaxSize: … Read more

[Solved] Use String isEmpty to check for empty string

The empty string is the only empty string, so there should be no cases where string.isEmpty() does not return the same value as string == “”. They may do so in different amounts of time and memory, of course. Whether they use different amounts of time and memory is an implementation detail not described, but … Read more

[Solved] expected Declaration (Won’t Compile) [duplicate]

Try this. I’m assuming the return true does not belong there. You can’t return a value outside of a method. override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { self.contacts.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .fade) } } solved expected Declaration (Won’t Compile) [duplicate]

[Solved] Value of type ” has no member ” in swift

The function retrieveContactsWithStore must be outside of the @IBAction @IBAction func btnContactsTapped() { let store = CNContactStore() if CNContactStore.authorizationStatus(for: .contacts) == .notDetermined { store.requestAccess(for: .contacts, completionHandler: { (authorized, error) in if authorized { self.retrieveContactsWithStore(store: store) } }) } else if CNContactStore.authorizationStatus(for: .contacts) == .authorized { self.retrieveContactsWithStore(store: store) } } func retrieveContactsWithStore(store: CNContactStore) { do { … Read more

[Solved] Store value from JSON to a variable [closed]

Based on this file https://pastebin.com/Z3vJsD77 you posted above. You can directly access the chargeLimitSOC property from this model like following – let chargeLimitSOC = chargeState.chargeLimitSOC Relevant part in your model is here – open class ChargeState: Codable { open var chargeLimitSOC: Int? enum CodingKeys: String, CodingKey { case chargeLimitSOC = “charge_limit_soc” } } 1 solved … Read more

[Solved] Update code to swift 2 [closed]

You have to use this code in try catch like below.. if let rtf = NSBundle.mainBundle().URLForResource(“rtfdoc”, withExtension: “rtf”) { do { let attributedString = try NSAttributedString(fileURL: rtf, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil) textView.attributedText = attributedString textView.editable = false print(attributedString) } catch let error as NSError { print(error.localizedDescription) } } solved Update code to swift 2 [closed]

[Solved] How to change multiple labels one at a time? – Swift

You can try this, you have to create an array of labels or a collection of labels. func assignLabel(){ if yourArray.count > labelsArrays.count { yourArray.removeFirst() } for i in 0..<yourArray.count { labelsArrays[i].text = yourArray[i] } } solved How to change multiple labels one at a time? – Swift

[Solved] How to create reminders that don’t have to be shown in the Apple’s Reminders app

Just for the record, what I was looking for was User Notifications. Here is a complete example. User Notifications func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { (granted, error) in if granted{ print(“User gave permissions for local notifications”) }else{ print(“User did NOT give permissions for local notifications”) } … Read more

[Solved] Bad: app building starts with black screen [closed]

It may come from your AppDelegate. Could you show us you AppDelegate ? Apple introduce SceneDelegate that can impact your AppDelegate. If you don’t want to use SceneDelegate, you should define the UIWindow in the AppDelegate : var window: UIWindow? and init your variable : window = UIWindow(frame: UIScreen.main.bounds) in func application(_ application: UIApplication, didFinishLaunchingWithOptions … Read more