swift - Custom variable setter with a default value -
i cannot create custom setter default value simple class. want implement custom tz setter timezone inspecting.
what's wrong?
public class city: nsobject { public var lat = 0.0, lon = 0.0, name = "" private static let def_tz = "gmt+00:00" private static let timezones = nstimezone.knowntimezonenames() public var tz: string = def_tz { set { //// <<<<< there error var = city.timezones.indexof(newvalue ?? city.def_tz) ?? 0 self.tz = timezones[i].name } { return self.tz } } // mark:- init required public init(name: string, lat: double, lon: double, tz: string) { super.init() setup(name, lat: lat, lon: lon, tz: tz) } private func setup(name: string, lat: double, lon: double, tz: string) { self.lat = lat self.lon = lon self.tz = tz == "" ? city.def_tz : tz self.name = name } }
the error
city.swift:16:9: use of unresolved identifier 'set'
the syntax of custom setter wrong here.
check correct 1 here: https://developer.apple.com/library/prerelease/content/documentation/swift/conceptual/swift_programming_language/properties.html
Comments
Post a Comment