[Solved] Parse ISO8601 in swift
You didn’t set the timezone of the output date, so it’s defaulting to your systems’ timezone rather than UTC (which is what you were expecting). solved Parse ISO8601 in swift
You didn’t set the timezone of the output date, so it’s defaulting to your systems’ timezone rather than UTC (which is what you were expecting). solved Parse ISO8601 in swift
You can do in following way: a.sort { return $0.last as! Int > $1.last as! Int } Don’t forget to add additional checks while using this code, case where the last item is not an integer or there is an array not in the expected format. Otherwise, it will lead to a crash. 0 solved … Read more
You may try the following: let numArray = [1, 2, 3, 3, 4, 5, 5] // Group by value let grouped = Dictionary(grouping: numArray, by: { $0 }) // Filter by its count, convert back to Array and sort let unique = Array(grouped.filter { $1.count == 1 }.map(\.key)).sorted() print(unique) // [1, 2, 4] Here is … Read more
Your class is basically right (though the setter for fullName isn’t handling anything other than fullNameArr.count == 3). class Person { var firstName: String var lastName: String var fullName: String { get { “\(firstName) \(lastName)” } set { let names = newValue.components(separatedBy: ” “) lastName = names.last ?? “” firstName = names.dropLast().joined(separator: ” “) } … Read more
cell.textLabel?.text can only show a String object, not other objects. It will be product.item or product.price or product.salesPrice or all in one line. (based on your requirement). Make sure the value of product is not nil. cell.textLabel?.text = “\(product.item) \(product.price) \(product.salesPrice)” The full code you can try this: class ViewController: UIViewController, UIAdaptivePresentationControllerDelegate { @IBOutlet weak … Read more
Swift ranges are written as 0…10, not [0…10]. [0…10] creates a single-item array. The first item in the array is a 0…10 range. Using for i in [0…10] thus iterates over that single-item array, not the range itself. The iterated value i will be of type Range or ClosedRange. To iterate over each Int in … Read more
To get a random image from your QuoteImages array you have to first get a random value and then request that from your array let randomValue = arc4random_uniform(10)+1 let randomImage = QuoteImages[randomValue] solved Cannot Assign Value of type ‘UIImage?’ to type ‘[UIImage]’ when generating a random image
Welcome to SO. This is not a site where you get other people to write your code for you. It’s a site to ask for help with code you write yourself. You want to use arc4random_uniform() to create a random number, and then scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: to fire your timer at a random time in the future. … Read more
Static values can be accessed without creating a class instance and are only created once per class, no matter how many instances you create. solved What static means in swift
This is how it works func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { // YOU SHOULD FIRST CHECK FOR THE BACKSPACE. IF BACKSPACE IS PRESSED ALLOW IT if string == “” { return true } if let characterCount = textField.text?.count { // CHECK FOR CHARACTER COUNT IN TEXT FIELD if … Read more
In your loop i will always be 1. You are using i + 1 for incrementing the counter variable but you are not assigning the value back. So either you use: for var i = 1; i < 10; i = i + 1 { println(i) } or for var i = 1; i < … Read more
There are a few errors I see: You need a space in /1005.967 after the / operator — there are likely other spots like this as well. Near the end of the expression, you have a floating sin that doesn’t have an operator before it and isn’t followed with parenthesis at all There are many … Read more
To add a view controller to another view controller, you can do the following: Inside the parent view controller class: addChildViewController(someViewController) view.addSubview(someViewController.view) someViewController.didMove(toParentViewController: self) someViewController.view.translatesAutoresizingMaskIntoConstraints = false Then, set the layout constraints to position the view controller: NSLayoutConstraint.activate([ someViewController.view.leadingAnchor .constraint(equalTo: view.leadingAnchor ), someViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), someViewController.view.bottomAnchor .constraint(equalTo: view.bottomAnchor ), someViewController.view.topAnchor .constraint(equalTo: view.topAnchor ) ]) view.layoutIfNeeded() 2 … Read more
Your previous question is quite close but you have to add the struct for the root object Declare the struct members non-optional as much as possible. The URLs can be decoded as URL struct Root : Decodable { let count : Int let recipes : [Recipe] } struct Recipe : Decodable { // It’s highly … Read more
self.presentViewController(cb_main_noticeView, animated: false, completion: nil) Juste remove the navigationController, if you don’t have a navigation controller in your app. solved How to navigate from xib to other xib in swift?