[Solved] Expected type after as

as? is use to cast one type to another, you are asking Xcode to cast response to another type, but haven’t told it what to cast it to. As the error says, its expecting to see a type after the keyword as 2 solved Expected type after as

[Solved] What is inheriting in swift 4

goto File > New > File or use shortcut key (COMMAND+N) Select Cocoa Touch Class Enter Class Name AddCommentsViewController Select Subclass of UIViewController Press Next and then press create. A new Cocoa Touch class named AddCommentsViewController is created inherit from UIViewController solved What is inheriting in swift 4

[Solved] How to implement this Python code in Swift?

First you should do is to properly define type of the graph, because unlike Python you have to specify types in Swift in declaration: var graph: [String: [String: Int]] // Dictionary(hash table) with keys of type String and values of type Dictionary<String, Int> Then you should initialize graph with some initial value, because in Swift … Read more

[Solved] Alert view with JSON data [closed]

Don’t use NSDictionary in swift. Use [String:Any]. Get all values of the dictionary and join the array of strings. And join the error with a new line as a separator. let jsonObj:[String: Any] = [“error”: [ “email”: [“The email has already been taken.”], “phone”: [“The phone has already been taken.”]] ] if let errorMsgs = … Read more

[Solved] Why does my JSON request fail more than 50% of the time? [closed]

There is not enough information to debug this specific problem but it is likely that the JSON response you are receiving has optional fields. Fields that are expected to be empty for certain responses. This part of your code, if let dictionary = jsonData as? [String: Any], let results = dictionary[“results”] as? [[String: Any]], !results.isEmpty, … Read more

[Solved] memory leak when calling an Api [closed]

You should refresh your memory (no pun intended) what a memory leak is. No, having thousands of entries in memory does not necessarily lead to memory leak (the main source of memory leaks in Swift are closures). It could, however, increase the memory pressure – which means your app could run out of free memory … Read more

[Solved] Swift 3 custom touch motion to trigger action [closed]

Well you question is divided into 2 parts and I’ll answer them both. 1- What you are looking for is UIGestureRecognizer where it’ll recognize a gesture and do an action accordingly. Here is a link taht will help you out! https://www.raywenderlich.com/76020/using-uigesturerecognizer-with-swift-tutorial 2- Unlocking the phone is impossible without jailbreak. Your gestures are bound to your … Read more

[Solved] Find x number of array elements closest to target [closed]

Let’s define some testing data. Let’s have a function: func getClosest(count: Int, from values: [Int], to targetNumber: Int) -> [Int] and we will test with the following: let array = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000] print(getClosest(count: 5, from: array, to: 1000)) print(getClosest(count: 5, … Read more

[Solved] How to get an string array from JSON arrays? [closed]

First of all you need to convert the raw response from the server to a Swift Dictionary. let payload = [ “cars”: [ [ “color”: “red”, “model”: “ferrari”, “othersAtributes”: “others atributes” ], [ “color”: “blue”, “model”: “honda”, “othersAtributes”: “others atributes” ], [ “color”: “green”, “model”: “ford”, “othersAtributes”: “others atributes” ], [ “color”: “yellow”, “model”: “porshe”, … Read more

[Solved] Swift 3 code update

I fixed your code using Swift 3 syntax. class SignUp: UIViewController { @IBOutlet weak var buttonNameTxt: UITextField! @IBOutlet weak var buttonEmailTxt: UITextField! @IBOutlet weak var buttonPwdTxt: UITextField! override func viewDidLoad() { super.viewDidLoad() } @IBAction func buttonSignIn(_ sender: UIButton) { let usermainname = buttonNameTxt.text! let username = buttonEmailTxt.text! let password = buttonPwdTxt.text! let myURL = URL(string: … Read more

[Solved] How to change JSON string to date format in tableview

In which format do you want to convert. Try this one with your desired format if let dateString = JSONList[indexPath.row].createdDate{ let dateFormatter = DateFormatter() dateFormatter.locale = Locale(identifier: “en_US_POSIX”) dateFormatter.dateFormat = “yyyy-MM-dd HH:mm:ss” dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) let date = dateFormatter.date(from: dateString) dateFormatter.dateFormat = “dd/MM/yyyy” let dateStr = dateFormatter.string(from:date!) cell.Date.text = dateStr } 0 solved How … Read more