Post

Replies

Boosts

Views

Activity

Reply to Trying to display on a collectionview cell.
I know they are nil because I tried to debug them and saw the values were nil so that was why they are not displaying. How can I display them then?ImageController is constant that takes the function fetchItemArtwork which takes a url and turns it into a UIImage. CurrentPlayer is my class with the values for update. This is my ViewControllerclass ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { @IBOutlet weak var collections: UICollectionView! @IBOutlet weak var theSearch: UISearchBar! var cPlayerArr = [CurrentPlayer]() override func viewDidLoad() { super.viewDidLoad() let layout = UICollectionViewLayout() downloadJSON { self.collections.reloadData() //print("***\(self.cPlayerArr)***") } self.collections.register(CurrentPlayerCell.self, forCellWithReuseIdentifier: "playercell") self.collections.delegate = self self.collections.dataSource = self } func downloadJSON(completed: @escaping () -> ()) { let url = URL(string: "https://api.sportsdata.io/v3/nba/scores/json/Players?key=apiKey") URLSession.shared.dataTask(with: url!) { (data, response, error) in if error == nil { do { //put data in here self.cPlayerArr = try JSONDecoder().decode([CurrentPlayer].self, from: data!) DispatchQueue.main.async { completed() } } catch { print("JSON Error") } } } .resume() } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { print(cPlayerArr.count) return cPlayerArr.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "playercell", for: indexPath) as! CurrentPlayerCell let item = cPlayerArr[indexPath.row] cell.update(with: item) return cell }
Mar ’20
Reply to Trying to display on a collectionview cell.
my text labels for example all have UILabel? nil. Part of my func update in the first question.Code 1: ImageControllerclass FetchImage { func fetchItemArtwork(url: URL, completion: @escaping (UIImage?) -> Void) { let task = URLSession.shared.dataTask(with: url) { (data, response, error) in if let data = data, let image = UIImage(data: data) { completion(image) } else { completion(nil) } } task.resume() } }Code 2: CurrentPlayer classimport Foundation struct CurrentPlayer: Codable, Hashable { let photoUrl: URL let firstName: String let lastName: String let positionCategory: String let team: String enum CodingKeys: String, CodingKey { case photoUrl = "PhotoUrl" case firstName = "FirstName" case lastName = "LastName" case positionCategory = "PositionCategory" case team = "Team" } init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) photoUrl = try values.decode(URL.self, forKey: CodingKeys.photoUrl) firstName = try values.decode(String.self, forKey: CodingKeys.firstName) lastName = try values.decode(String.self, forKey: CodingKeys.lastName) positionCategory = try values.decode(String.self, forKey: CodingKeys.positionCategory) team = try values.decode(String.self, forKey: CodingKeys.team) } }
Mar ’20
Reply to Transfer From Parent To Child
Okay this is the code for one of my sliders in a child view. I want the calROA() method from the parent to be avaliable in the cAssMove function. @IBAction func cAssMove(_ sender: Any) {     cAssetsHeight.constant = CGFloat(cAssetsSlider.value)     scaleCA = Int(6.75675675676 * cAssetsSlider.value)     cAssetsNum.text = "\(scaleCA)"     if scaleCA < 316 {       cAssetsLabel.text = ""     } else {       cAssetsLabel.text = "Current \n Assets"     }       }
Sep ’20