[Solved] I get an Swift Decoding error: parsing JSON, found an Array expected a Dictionary? [duplicate]

Your json seems to be an array of Items, and not an object with a property named todoitems, so do this instead: let decodedData = try decoder.decode([Items].self, from: todoData) fetchedTitle = decodedData[1].title Your ToDoData struct can’t be used in this scenario, since your json doesn’t contain a property named todoitems. 0 solved I get an … Read more

[Solved] How to build Swift Multi Array

Create a struct/class with the relevant properties and then create an array of that struct/class type, i.e. struct Person { let id: Int let name: String let age: Int } Now, create an array of Person type let arr = [Person(id: 1, name: “Jim Willson”, age: 35), Person(id: 2, name: “Bill Karry”, age: 48), Person(id: … Read more

[Solved] Replace occurrences in String

Create an array with the new strings. Find the range of first matching substring “black” in the string using range(of:). And replace with the new string in the range using replaceSubrange(_:with:) method. Then continue the loop till last element of the array. var mString = “my car is black, my phone is black” [“blue”,”red”].forEach { … Read more

[Solved] iOS Error: Cannot convert value of type ‘UserModel’ to expected argument type ‘[String : Any]’

You have to convert your UserModel to [String : Any] type in order to save it on firebase. Try this: func convertUserModelToDictionary(user: UserModel) -> [String : Any] { let userData = [ “name” : user.name, // change these according to you model “email”: user.email, “user_id”: user.userId ] return userData } You can use this function … Read more

[Solved] How to build this layout in Swift

Best way is to use a UITableViewController. With that you can implement all the cells easily and efficiency. Then drag and drop an imageView on top of the tableView in the UITableViewController. You can place it right between the tableView and the Top to get what you want. solved How to build this layout in … Read more

[Solved] Filter not working in model object – swift

Your structs: struct User { var name: String var age: Int var hasPet: Bool var pets: [Pet] } struct Pet { var id: Int var petName: String var colour: String } User and pets objects: let pet1 = Pet(id: 1, petName: “Lucy”, colour: “black, white”) let pet2 = Pet(id: 2, petName: “Nemo”, colour: “white”) let … Read more

[Solved] how to make Dyanamic NSDictonary in Swift

You can use swift Dictionary [String: AnyObject] this way instead of NSMutableDictionary. var data = [[String: AnuObject]]() for i in 0..<questionArr.count { data.append([“QuestionID”: questionArr[i], “AnswerID”: answerArr[i]]) } let dic = [ “QuizId” : “23566656”, “StartTime” : “23:30”, “EndTime” : “23:45”, “data” : data ] print(dic) 20 solved how to make Dyanamic NSDictonary in Swift

[Solved] Swift Xcode 6 baseball Counter

Use a property observer: var counter = 1 { didSet { if counter == 3 { self.outsCounter++ } } } Whenever counter gets changed, didSet will be called. (Also note that the equality operator is ==. = is for assignment.) 0 solved Swift Xcode 6 baseball Counter

[Solved] How to group Arrays [duplicate]

You can extend Collection, constrain its Element to Equatable protocol and create a computed property to return the grouped elements using reduce(into:) method. You just need to check if there is a last element on the last collection equal to the current element and append the current element to the last collection if true otherwise … Read more

[Solved] How to open external link from UIWebView not in my App, but in Safari? SWIFT

@Leo Dabus thanks a lot for this hint, but I guess I have a better solution: func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool { if navigationType == UIWebViewNavigationType.LinkClicked{ UIApplication.sharedApplication().openURL(request.URL!) return false } return true } this one works perfect. solved How to open external link from UIWebView not in my App, but … Read more