I've got an osx xcode project created with xcode 6.1 I wanted to use it to train using with SWIFT a little bit.
In one of my views I tried creating an NSBitMapImageRep as seen here:
class BitmapView : NSView {
var image: NSBitmapImageRep!
override func awakeFromNib() {
var blub = NSBitmapImageRep(bitmapDataPlanes: nil,
pixelsWide: Int(self.frame.size.width),
pixelsHigh: Int(self.frame.size.height),
bitsPerSample: 8,
samplesPerPixel: 1,
hasAlpha: false,
isPlanar: false,
colorSpaceName: NSCalibratedRGBColorSpace,
bytesPerRow: 0, bitsPerPixel: 0)!
//test()
}}
But every time I try running it, I get the following error:
Inconsistent set of values to create NSBitmapImageRep fatal error: unexpectedly found nil while unwrapping an Optional value
Which I guess is due to bitmapDataPlanes being nil. But it is an optional value and according to the documentation is allowed to be NULL. Passing NSNull() instead doesn't compile though.
Can anybody tell me what I would have to pass instead? o_O
The error is actually fairly descriptive - you're providing an inconsistent set of values to the initializer. Specifically, the
samplesPerPixel
value of 1 can't support a RGB color space, which you specify incolorSpaceName
. From here:So you just need to change the samples per pixel to 3: