Post

Replies

Boosts

Views

Activity

Reply to Having problems accessing data out of dictionary.
Thank you! I appreciate the response! I tried and I am getting the following: Value of optional type 'AnyObject?' must be unwrapped to refer to member 'subscript' of wrapped base type 'AnyObject' Chain the optional using '?' to access member 'subscript' only for non-'nil' base values Force-unwrap using '!' to abort execution if the optional value contains 'nil' Value of type 'Any??' has no subscripts I add '?' in between videos and mp4 like the error above suggestions and I get the following: Value of type 'Any??' has no subscripts
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
So I was successfully able to decode the JSON and I parse it but now I am having issues copying everything to array so I can assign them to UIImageView, UILabel and UIButton. Can someone help again? Here is the array definition var videos: [String] = [] Here it the loop. let result = try? JSONDecoder().decode(Kaiserclixresponse.self, from: data)             if let result = result {                 result.response.rows.forEach {                                        let movie = $0                     videos.append(movie) { but I keep getting No exact matches in call to instance method 'append' Open to suggestions on a better way of doing this.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
So I changed the structure in attempt to follow the hierarchal tree because I keep getting nil when trying to print out what I thought would be the title. I have trying a lot of different lines of code just to print out one of the key value pairs. With no luck. Keep getting nil. I must be doing something wrong. Can some one help? Here is the update swift file containing the structures. // //  claude31.swift //  GetData // //  Created by Gregory Kaiser on 9/8/22. // import Foundation struct MP4: Codable {     var _480: String? } struct Videos: Codable {     var mp4: MP4? }   struct ROWS: Codable {     var title:String?     var description:String?     var Poster:String? } struct RESP: Codable{     var totalRows: Int     var rows: [ROWS] } struct Kaiserclixresponse : Codable {     var error: Bool     var message: String?     var resp: RESP } Here is the viewController code trying to access the JSON // //  ViewController.swift //  GetData // //  Created by Gregory Kaiser on 9/6/22. // import UIKit class ViewController: UIViewController {     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.                  // Hit the API endpoint         guard let url =  URL(string:"https://videos.kaiserclix.com/AVideo/plugin/API/get.json.php?APIName=video&user=gkaiser63@gmail.com&pass=abc123") else {             fatalError("Invalid URL")         }                                URLSession.shared.dataTask(with: url) { (data, response, error) in                      // Check for errors             guard let data = data, error == nil else {                 return             }                          //Parse JSON                                      let result = try? JSONDecoder().decode(Kaiserclixresponse.self, from: data)             if let result = result {                 print(result.resp.rows[0].Poster!)             }          }.resume()      } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
Thank you so much for responding! So the missing 'h' was me removing it. I copied the JSON into Word with the hopes of covering up the private information and the urls and removed the 'h' to stop it appearing as link. When you a little bit of work that didn't need up working when attaching here. :-( I have been watching/researching online to learn Swift and somebody suggesting making things optional if you are not sure if the key is always present. I believe row is an array. It has 22 items. Thank you for the tutorial! I will have a look.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
Here is the two swift files I came up with. // //  videoFeed.swift //  GetData // //  Created by Gregory Kaiser on 9/6/22. // import Foundation struct videoFeed: Codable {     var error: Bool     var message: String?     struct response: Codable{         var totalRows: String?         var rows: [row]     } Here is the second one // //  vids.swift //  GetData // //  Created by Gregory Kaiser on 9/6/22. // import Foundation struct row: Codable {     var title:String?     var desciption:String?     var Poster:String?     struct videos: Codable {         struct mp4: Codable {             var _480: String?         }     } } Can someone tell me if these are correct? And how do I access each item grabbing the link in videos.mp4.480? Thank you! }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’22
Reply to Having problems accessing data out of dictionary.
So here my current code. if let link = movieDict["videos"]?["mp4"]?["480"]? as? String? {             print(link)             self.videoLink = link         } It is getting: Type of expression is ambiguous without more context
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to Having problems accessing data out of dictionary.
Thank you! I appreciate the response! I tried and I am getting the following: Value of optional type 'AnyObject?' must be unwrapped to refer to member 'subscript' of wrapped base type 'AnyObject' Chain the optional using '?' to access member 'subscript' only for non-'nil' base values Force-unwrap using '!' to abort execution if the optional value contains 'nil' Value of type 'Any??' has no subscripts I add '?' in between videos and mp4 like the error above suggestions and I get the following: Value of type 'Any??' has no subscripts
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
So I was successfully able to decode the JSON and I parse it but now I am having issues copying everything to array so I can assign them to UIImageView, UILabel and UIButton. Can someone help again? Here is the array definition var videos: [String] = [] Here it the loop. let result = try? JSONDecoder().decode(Kaiserclixresponse.self, from: data)             if let result = result {                 result.response.rows.forEach {                                        let movie = $0                     videos.append(movie) { but I keep getting No exact matches in call to instance method 'append' Open to suggestions on a better way of doing this.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
Thanks again!
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
Thank you! Greatly appreciated! Changing resp to response worked! I am pretty sure I read/heard the var names didn't have to match the JSON key names and I was seeing issues with a variable name response so I shortened it to resp. Take care!
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
So I changed the structure in attempt to follow the hierarchal tree because I keep getting nil when trying to print out what I thought would be the title. I have trying a lot of different lines of code just to print out one of the key value pairs. With no luck. Keep getting nil. I must be doing something wrong. Can some one help? Here is the update swift file containing the structures. // //  claude31.swift //  GetData // //  Created by Gregory Kaiser on 9/8/22. // import Foundation struct MP4: Codable {     var _480: String? } struct Videos: Codable {     var mp4: MP4? }   struct ROWS: Codable {     var title:String?     var description:String?     var Poster:String? } struct RESP: Codable{     var totalRows: Int     var rows: [ROWS] } struct Kaiserclixresponse : Codable {     var error: Bool     var message: String?     var resp: RESP } Here is the viewController code trying to access the JSON // //  ViewController.swift //  GetData // //  Created by Gregory Kaiser on 9/6/22. // import UIKit class ViewController: UIViewController {     override func viewDidLoad() {         super.viewDidLoad()         // Do any additional setup after loading the view.                  // Hit the API endpoint         guard let url =  URL(string:"https://videos.kaiserclix.com/AVideo/plugin/API/get.json.php?APIName=video&user=gkaiser63@gmail.com&pass=abc123") else {             fatalError("Invalid URL")         }                                URLSession.shared.dataTask(with: url) { (data, response, error) in                      // Check for errors             guard let data = data, error == nil else {                 return             }                          //Parse JSON                                      let result = try? JSONDecoder().decode(Kaiserclixresponse.self, from: data)             if let result = result {                 print(result.resp.rows[0].Poster!)             }          }.resume()      } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
Thank you so much for responding! So the missing 'h' was me removing it. I copied the JSON into Word with the hopes of covering up the private information and the urls and removed the 'h' to stop it appearing as link. When you a little bit of work that didn't need up working when attaching here. :-( I have been watching/researching online to learn Swift and somebody suggesting making things optional if you are not sure if the key is always present. I believe row is an array. It has 22 items. Thank you for the tutorial! I will have a look.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to New to Swift. Need help mapping class files to JSON
Here is the two swift files I came up with. // //  videoFeed.swift //  GetData // //  Created by Gregory Kaiser on 9/6/22. // import Foundation struct videoFeed: Codable {     var error: Bool     var message: String?     struct response: Codable{         var totalRows: String?         var rows: [row]     } Here is the second one // //  vids.swift //  GetData // //  Created by Gregory Kaiser on 9/6/22. // import Foundation struct row: Codable {     var title:String?     var desciption:String?     var Poster:String?     struct videos: Codable {         struct mp4: Codable {             var _480: String?         }     } } Can someone tell me if these are correct? And how do I access each item grabbing the link in videos.mp4.480? Thank you! }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22