Reputation: 327
Currently my class that fills my collection view is simple:
class Search {
// MARK: - Public API
var className = ""
var tutorCenterName = ""
init(className: String, tutorCenterName: String) {
self.className = className
self.tutorCenterName = tutorCenterName
}
// MARK: - Private
static func createSearches() -> [Search]
{
return [
Search(className: "AC311", tutorCenterName: "ACELAB"),
Search(className: "CS280", tutorCenterName: "CIS Sandbox")
]
}
}
The problem is that createSearches() returns only those hard coded Search objects. I would like to have the user create Search objects in another class that would then add to this array, eventually creating a list of what the user searched for. For some reason I cannot get createSearches() to return an array variable, only a hard coded array of Search objects. Is there a way I can get around this?
Upvotes: 0
Views: 40
Reputation: 26
If you want the Search
class to keep a list of search
objects, you could use a class variable, like so:
static var searches: [Search]
along with the appropriate class level methods to control access to it.
Upvotes: 1