Post

Replies

Boosts

Views

Activity

Reply to How to save the state of a Switch
I figured out how to save the state of the switch when the state of the switch is changed. Thanks for your help on getting me there. class SettingsCustomCell: UITableViewCell { //... @IBAction func switchValueChanged(_ sender: UISwitch) {         state?.settingValue = sender.isOn         let defaults = UserDefaults.standard         defaults.set(quickAddSwitch.isOn, forKey: "quickAdd")     } } class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource { //... override func viewDidLoad() {         super.viewDidLoad()         cellStates = [             SettingsState(settingLabel: "Quick Add", settingValue: (UserDefaults.standard.bool(forKey: "quickAdd")))         ]     } }
Sep ’21
Reply to How to save the state of a Switch
OK so I rewrote some code, class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource {          var data = [Settings_Custom_Cell]()          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return data.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         data = [SettingsCell(settingLabel: "Quick Add", settingValue: <#UISwitch#> )]         let cell = table.dequeueReusableCell(withIdentifier: "cell") as! Settings_Custom_Cell         let array = data[indexPath.row]         cell.textLabel?.text = array.settingLabel.text         cell.settingValue.isOn = array.settingValue.isOn         cell.textLabel?.numberOfLines = 0         cell.textLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping         cell.textLabel?.font = UIFont.systemFont(ofSize: 20)         return cell     }     @IBOutlet weak var table: UITableView!     override func viewDidLoad() {         super.viewDidLoad()     }      } I am not sure if I am on the right track but what do I put in the 'settingValue' value in data = [SettingsCell(settingLabel: "Quick Add", settingValue: <#UISwitch#> )]
Sep ’21
Reply to How to save the state of a Switch
OK so I rewrote some code, class Settings: UIViewController, UITableViewDelegate, UITableViewDataSource {          var data = [Settings_Custom_Cell]()          func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {         return data.count     }          func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {         data = [SettingsCell(settingLabel: "Quick Add", settingValue: <#UISwitch#> )]         let cell = table.dequeueReusableCell(withIdentifier: "cell") as! Settings_Custom_Cell         let array = data[indexPath.row]         cell.textLabel?.text = array.settingLabel.text         cell.settingValue.isOn = array.settingValue.isOn         cell.textLabel?.numberOfLines = 0         cell.textLabel?.lineBreakMode = NSLineBreakMode.byWordWrapping         cell.textLabel?.font = UIFont.systemFont(ofSize: 20)         return cell     }     @IBOutlet weak var table: UITableView!     override func viewDidLoad() {         super.viewDidLoad()     }      } I am not sure if I am on the right track but what do I put in the 'settingValue' value in data = [SettingsCell(settingLabel: "Quick Add", settingValue: <#UISwitch#> )]
Sep ’21
Reply to How do I retrieve data from an API?
Response is defined import Foundation struct Response: Codable {     let results: Player_Data     let status: String } struct Player_Data: Codable {     let playerID: String     let position: String     let displayName: String     let fname: String     let team: String     let byeWeek: String     let standDev: String     let nerdRank: String     let positionRank: String     let overallRank: String } The error is failed to convert keyNotFound(CodingKeys(stringValue: "results", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"results\", intValue: nil) (\"results\").", underlyingError: nil))
Aug ’20
Reply to How do I create an array of a class?
1. I tried implementing didSelectRowAt function but how do I implement it that when a row is selected with the league name that it will segue to another view controller load the players for that selected league in a table view?3. Yes, table in destination VC. I setup a segue in storyboard to segue to another view controller to load myLeaguePlayersData.4. The destination VC class is MyLeague_2019class MyLeague_2019: UIViewController, UITableViewDelegate, UITableViewDataSource { var players: [[PlayerData]] = [[]] override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) players = Database_2019.shared.myLeaguePlayersData } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int { return players[section].count } func numberOfSections(in tableView: UITableView) -&gt; Int { return players.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell { let players = Database_2019.shared.myLeaguePlayersData[indexPath.section][indexPath.row] let cell = table.dequeueReusableCell(withIdentifier: "cell", for: indexPath) cell.textLabel?.text = "\(indexPath.row+1). \(players.name), \(players.team) - \(players.position)" cell.textLabel?.adjustsFontSizeToFitWidth = true cell.textLabel?.font = UIFont.systemFont(ofSize: 22) return cell } @IBOutlet weak var table: UITableView! }5. Yes, I want to pass the whole myLeaguePlayersData to the destination.Yes, I do need to declare as an array of PlayerData.Yes, I do want to keep in memory that those players are added as a group.
Feb ’20
Reply to How do I create an array of a class?
var myLeaguePlayers is an array of players.var myLeaguePlayersData is an array of the added leagues players.myLeaguePlayers = [Aaron Rodgers, GB - QB, Alvin Kamara, NO - RB, Tyreek Hill, KC - WR] myLeaguePlayersData = [[Patrick Mahomes, KC - QB, David Johnson, ARI - RB, Michael Thomas, NO - WR], [Matt Ryan, ATL - QB, Joe Mixon, CIN - RB], [Aaron Rodgers, GB - QB, Alvin Kamara, NO - RB, Tyreek Hill, KC - WR]]myLeaguePlayers is the current players in the league. I want to append myLeaguePlayers to myLeaguePlayersData.I do have myLeaguePlayers and myLeaguePlayersData initialized. I didn't show it but here it is:init() { myLeagues = [String]() myleaguePlayers = [PlayerData]() myLeaguePlayersData = [[PlayerData]]() }
Feb ’20
Reply to How do I create an array of a class?
var myLeagues: [String] is the list of league names.var myLeaguePlayers: [PlayerData} is the players.var myLeaguePlayersData: [[PlayerData]] is an array of the players.For instance, I want to be able to append myLeaguesPlayers to myLeaguePlayersData when a league is added but I want the added myLeaguePlayers to be connected to the added myLeagues.The result I want is when the added leagues row is clicked, it will segue to another view controller and load the connected myLeaguePlayersData element inb a table.What is your sugestion on how to do this?
Feb ’20