You can make it work with variables and call super.init() (to create self before accessing its properties):
class Test: NSObject { var filePath: NSString! var _fileHandle: NSFileHandle! var _totalFileLength: CUnsignedLongLong! init?(filePath: String) { super.init() if let fileHandle = NSFileHandle(forReadingAtPath: filePath) { self.filePath = filePath self._fileHandle = NSFileHandle(forReadingAtPath: filePath) self._totalFileLength = self._fileHandle.seekToEndOfFile() } else { return nil } } }
But if you plan to stick to your version with constants, then this is from my comfort zone and perhaps this answer may help.
source share