[Solved] How to fix the setter of the fullName property to enable an automatic update for the firstName and lastName properties? [closed]

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

[Solved] Im getting an error at cellForRowAt and im not sure why

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

[Solved] Cannot Assign Value of type ‘UIImage?’ to type ‘[UIImage]’ when generating a random image

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

[Solved] Dismiss keyboard after a user entered 11 digit [duplicate]

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

[Solved] For loop runs forever

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

[Solved] Present a viewcontroller in UIView [closed]

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

[Solved] Using JSON Decodable in Swift 4.1

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