mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Classes are exactly like structs except that they may have a base class. However, this type will show up in the inheritance list. That means we don't actually need to serialize it twice; we can just grab the base class from the inheritance list. Swift SVN r6133
74 lines
1006 B
Swift
74 lines
1006 B
Swift
class Empty {}
|
|
|
|
class TwoInts {
|
|
var x, y : Int
|
|
|
|
constructor(a : Int, b : Int) {
|
|
x = a
|
|
y = b
|
|
}
|
|
}
|
|
|
|
class ComputedProperty {
|
|
var value : Int {
|
|
get:
|
|
var result : Int
|
|
return result
|
|
}
|
|
}
|
|
|
|
// Generics
|
|
class Pair<A, B> {
|
|
var first : A
|
|
var second : B
|
|
|
|
constructor(a : A, b : B) {
|
|
first = a
|
|
second = b
|
|
}
|
|
}
|
|
|
|
class GenericCtor<U> {
|
|
constructor<T>(t : T) {}
|
|
|
|
func doSomething<T>(t : T) {}
|
|
}
|
|
|
|
// Protocols
|
|
protocol Resettable {
|
|
func reset()
|
|
}
|
|
|
|
class ResettableIntWrapper : Resettable {
|
|
var value : Int
|
|
func reset() {
|
|
var zero : Int
|
|
value = zero
|
|
}
|
|
}
|
|
|
|
protocol Computable {
|
|
func compute()
|
|
}
|
|
|
|
typealias Cacheable = protocol<Resettable, Computable>
|
|
|
|
protocol SpecialResettable : Resettable, Computable {}
|
|
|
|
|
|
// Inheritance
|
|
|
|
class StillEmpty : Empty, Resettable {
|
|
func reset() {}
|
|
}
|
|
|
|
class BoolPair : Pair<Bool, Bool> {
|
|
func bothTrue() -> Bool {
|
|
return first && second
|
|
}
|
|
}
|
|
|
|
class SpecialPair<A> : Computable, Pair<Int, Int> {
|
|
func compute() {}
|
|
}
|