[Solved] selected and deselected checkbox in Swift

try this below code if let button = sender as? UIButton { if button.isSelected { // set selected button.isSelected = true } else { // set deselected button.isSelected = false } } For shorthand, try this if let button = sender as? UIButton { button.isSelected = !button.isSelected } 1 solved selected and deselected checkbox in … Read more

[Solved] How to turn Any into Data

Could you make it easy for me to understand how it works? It doesn’t. The whole meaning of Any is that it could be anything. But not just anything can be turned into a Data. That is why protocols like Codable and NSCoding (to which SCNNode conforms) exist — and why Any cannot conform to … Read more

[Solved] How to get random value from struct

If you want to keep it packed in some type you better use enum instead: enum RandomMessage: String, CaseIterable { case message1 = “Message1” case message2 = “Message2” case message3 = “Message3” case message4 = “Message4” case message5 = “Message5” static var get: String { return allCases.randomElement()!.rawValue } } This way you will guarantee that … Read more

[Solved] How soon can I release a watchOS app?

Apple will probably not begin to accept apps created for watchOS 2 before we get closer to the actual release of the operative system. As a reference, Apple started to ask developers to submit their apps targeted Apple Watch (the first version of the OS) on march 31, only about 25 days before the release … Read more

[Solved] How to get number of weeks by month in year?

As already mentioned NSCalendar has a method rangeOfUnit:inUnit:forDate:. The proper calendar units are CalendarUnitWeekOfYear and CalendarUnitMonth The result might be different for the locale and first weekday of the week settings. let calendar = NSCalendar.currentCalendar() let weekRange = calendar.rangeOfUnit(NSCalendarUnit.CalendarUnitWeekOfYear, inUnit: .CalendarUnitMonth, forDate: NSDate()) let weekArray = Array(weekRange.location..<weekRange.location + weekRange.length) Swift 3: let calendar = Calendar.current … Read more

[Solved] Avoid duplicates while adding in dictionary

Try this code to avoid duplication I hope “id” value will be unique in your dictionary. var mydictionary = [“id”: “1”, “quantity”: “”,”sellingPrice”:””] as [String : Any] var arrayOfDictionary = [Dictionary<String, Any>]() //declare this globally let arrValue = arrayOfDictionary.filter{ (($0[“id”]!) as! String).range(of: mydictionary[“id”]! as! String, options: [.diacriticInsensitive, .caseInsensitive]) != nil } if arrValue.count == 0 … Read more

[Solved] How to wait core data add functions step by step in swift 3

try using completion handler for your function or may try Operation queue with dependency to wait coreDataAdd (where : “User”, onCompletion: { (isFinished) in if isFinished { coreDataAdd (where : “Profile”, onCompletion: { (isFinished) in if isFinished { coreDataAdd (where : “Profile”, onCompletion: { (isFinished) in if isFinished //Here segue to the next view let … Read more

[Solved] Refresh or reload data in function ViewWillAppear not always working in UITableViewcontroller

There are two things you should consider. First reload data will be called right away after reloadTransaction() if your url request hasn’t processed yet, it will show an empty tableView. Second, when you have new data make sure to call the main thread before you call self.tableView.reloadData(): internal func reloadTransaction(){ self.transactionList.removeAll() //get URL response and … Read more