I think I am having a little problem with how to have data from model ready at run time to use in my TableViewController.
TeamModel
class TeamModel {
// a type of team
typealias Team = (String, Int, Int, Int)
// current list of teams
var teamList : [Team] = [("Manchester", 2, 40, 11)]
// adds a new team to the user's list of teams
func addTeamToDB(newTeam: Team) {
}
}
ViewController
class TeamViewController: UITableViewController {
// reference to team Model
let teamModelPointer = TeamModel()
let teams = teamModelPointer.teamList
Getting the error: Instance member TeamModelPointer cannot be used on type TeamViewController
Eventually this will have data in Core Data, so thatâs why I placed it in my model, I just wanted to see it work with arrays of Tuples initially. If I created the Array of Tuples in the controller, code works fine, which is why I think itâs a timing issue??
I canât find the problem. I do see there is no âTeamModelPointerâ in what you have pasted though - only a âteamModelPointerâ. Where exactly does the error occur and have you pasted everything accurately? Is there perhaps a âTeamModelPointerâ somewhere in the view controller, maybe you have tried to define an instance variable of that type?
Iâm not sure either. I just adjusted it to this:
class TeamViewController: UITableViewController {
// reference to team Model
let teams = TeamModel.teamList
Just so you know my mind set, Iâm trying to set the let of teams using the TeamModel class I have and the variable teamList I have defined inside of the TeamModel as noted in the code. IS that the correct way to call a model and property from a controller?
The error I get now is: instance member teamList cannot be used on type 'TeamModel'
You can also use the concept of âSingletonâ here to access data from the model . Create a âsharedInstanceâ object of the model class and you get access to methods and variables .
But i am not sure whether its the best approach , but surely that works .