Posts

Post marked as solved
5 Replies
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")))         ]     } }
Post marked as solved
5 Replies
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#> )]
Post not yet marked as solved
7 Replies
Yes, I looked, found some stuff on Stack Overflow but everything is confusing. Can you point me in the right direction of a good article please?
Post not yet marked as solved
7 Replies
How do I use a server without having to pay? Is there any free ones? If not, how do I use keychain?
Post not yet marked as solved
7 Replies
Okay how do I save it somewhere else? Is there a way to save it somewhere else other than a server?
Post marked as solved
7 Replies
It looks like the API is in a dictionary? Does that matter on how I format the Struct? Here is the actual API https://www.fantasyfootballnerd.com/service/draft-rankings/json/fmt8fvc8xg2s/1/
Post marked as solved
7 Replies
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))
Post marked as solved
7 Replies
Yes, the leading whitespace had to be removed but now it is executing line 21 - 23. The error is 'The data couldn’t be read because it isn’t in the correct format.' Thank you for your help.
Post not yet marked as solved
8 Replies
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.
Post not yet marked as solved
8 Replies
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]]() }
Post not yet marked as solved
8 Replies
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?
Post marked as solved
3 Replies
Thank you. It worked.I created another variable in databasefileprivate var allPlayersReset: [PlayerData]Then I initialized it by creating another data set.Then I created a function and set allPlayers = allPlayersReset.func resetDraft() { allPlayers = allPlayersReset }It works perfect.
Post marked as solved
5 Replies
Yes this worked. I had to add it in viewWillAppear though.
Post marked as solved
5 Replies
That hides the back button. I am trying to hide a different button that I created in the navigation bar.
Post marked as solved
18 Replies
I figured it out.I changed my PlayerData class to this:class PlayerData: Codable { var num: Int = 0 var numPosPick: Int = 0 var numRookie: Int = 0 var name: String = "" var team: String = "" var position: String = "" var rosterPosition: Int = -1 var draftPosition: Int = -1 var isTopPlayer: Bool var isRookie: Bool var isRostered: Bool { return rosterPosition &gt;= 0 } var isDrafted: Bool { return draftPosition &gt;= 0 } init(num: Int, numPosPick: Int, numRookie: Int, name: String, team: String, position: String, isTopPlayer: Bool, isRookie: Bool) { self.num = num self.numPosPick = numPosPick self.numRookie = numRookie self.name = name self.team = team self.position = position self.isTopPlayer = isTopPlayer self.isRookie = isRookie } }Adding isTopPlayer and isRookie to confirm if the player is in the top 200 or if the player is a rookie or if the player is both.I had to do a few tweaks but it works just the way I want it to now.