Classes can now have static methods and properties
About 2 min
Classes can now have static methods and properties 관련
HACKING WITH SWIFT
What's new in Swift?
Classes can now have static methods and properties | Changes in Swift 1.2
Classes can now have static methods and properties
Available from Swift 1.2
Swift 1.2 gives us an alias for class final properties: static
. While class variables may be overridden in subclasses, static variables may not. For example:
class Student: Person {
// THIS ISN'T ALLOWED
override static var count: Int {
return 150
}
// THIS IS ALLOWED
override class var averageAge: Double {
return 19.5
}
}
In this usage, static var
is merely an alias for final class var
.
Other changes in Swift 1.2…
The zip() function joins two sequences | Changes in Swift 1.2
The zip() function joins two sequences
The flatMap() method transforms optionals and arrays | Changes in Swift 1.2
The flatMap() method transforms optionals and arrays
Closures can now be marked @noescape | Changes in Swift 1.2
Closures can now be marked @noescape
Constants no longer require immediate initialization | Changes in Swift 1.2
Constants no longer require immediate initialization
A new Set data structure | Changes in Swift 1.2
A new Set data structure
Implicit bridging has been reduced | Changes in Swift 1.2
Implicit bridging has been reduced
Multiple if let bindings | Changes in Swift 1.2
Multiple if let bindings
Typecasting now includes as! | Changes in Swift 1.2
Typecasting now includes as!