[swift-users] NSMutableData's init?(length length: Int) initializer

soyer soyer at irl.hu
Thu Apr 14 12:45:36 CDT 2016


Hello Guys, Girls,

Do you know why is the init?(length length: Int) NSMutableData's initializer failable?
The memory allocation can fail, but I think Swift doesn't handle that cases. (it is not a real issue in a modern OS)
The code on github calls a non failable initializer.
https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSData.swift#L904

public convenience init?(length: Int) {
	let memory = malloc(length)
	self.init(bytes: memory, length: length, copy: false) { buffer, amount in
		free(buffer)
	}
}

Thanks
s


More information about the swift-users mailing list