Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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
      }
    }
  }


I see. Not really such a big deal in practice, but nice to have.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: