3 ms·
Swift doesn't have a designated base class like Java, C#, or Objective-C's NSObject. It seems, though, that there are a bunch of interop considerations which me
by austinz 12y ago
Swift doesn't have a designated base class like Java, C#, or Objective-C's NSObject. It seems, though, that there are a bunch of interop considerations which means that you might need your Swift classes to inherit from NSObject for them to work properly with Cocoa code.
Swift also doesn't perform type erasure. You can do something like the following, as I believe is possible in C#:
struct SquareMatrix<T> {
let dimension: Int
var backingArray: Array<T>
init(dimension d: Int, initialValue: T) {
dimension = d
backingArray = T[](count:d*d, repeatedValue:initialValue)
}
subscript(row: Int, col: Int) -> T {
get {
return backingArray[row*dimension + col]
}
set {
backingArray[row*dimension + col] = newValue
}
}
}
- mercurial 12y agoI see. Not really such a big deal in practice, but nice to have.