Static vs class functions/variables in Swift classes? -
the following code compiles in swift 1.2:
class myclass { static func mymethod1() { } class func mymethod2() { } static var myvar1 = "" } func dosomething() { myclass.mymethod1() myclass.mymethod2() myclass.myvar1 = "abc" }
what difference between static function , class function? 1 should use, , when?
if try define variable class var myvar2 = ""
, says:
class stored properties not yet supported in classes; did mean 'static'?
when feature supported, difference between static variable , class variable (i.e. when both defined in class)? 1 should use, , when?
(xcode 6.3)
static
, class
both associate method class, rather instance of class. difference subclasses can override class
methods; cannot override static
methods.
class
properties theoretically function in same way (subclasses can override them), they're not possible in swift yet.
Comments
Post a Comment