how do I not use a static var and return true or false here as it changes UI for every cell rather than for selected cell - obviously
could use UserDefaults but using that for selection/deselction of cell sounds weird . . .? idk β using chained delegation to send this cell from the view model to the controller, hence the issue
enum CellType: CustomStringConvertible {
static var returnValue: Bool = false
var selected: Bool {
get {
return returnValue
}
nonmutating set {
returnValue = newValue
}
}
}
Should have posted this chunk of code
enum CellType {
static var returnValue: Bool = false
var selected: Bool {
get {
return CellType.returnValue
}
nonmutating set {
CellType.returnValue = newValue
}
}
}
doesnβt quite solve my problem as it is not even associated with this at this point, haha - but using Self looks better (any other plusses?) than me using CellType. [not in the piece of code I posted]
Hi @lganti,
When you create a class or a struct, all properties are part of the instance. Instance is when you instantiate a class. For example,
struct One {
var name: String
}
let one = One(name: "Uno")
print(one.name) // Uno
However when you use static variables, they are unavailable for the structure or its functions/methods.
static properties or functions are similar to class functions, i.e. they are available to the structure or class not the instance.
struct Two {
static var language = "Italian"
var name: String
}
let two = Two(name: "Dos")
print(two.name) // Dos
print(two.langauge) // ERROR - static properties are not available in the instance
print(Two.language) // Italian - Available on the structure/class
lastly, the Self is not the same as self as lowercased self refers to the instance and the uppercased Self refers to the structure and provides the static properties and functions.
Hi @lewis-h,
There seems to be a disconnect between your response and the original question, do you want to fill in the gaps to what is it that you are trying to resolve.