【发布时间】:2014-11-17 18:04:43
【问题描述】:
我有一个使用 xcode 6.1 创建的 osx xcode 项目 我想用它来训练一下使用 SWIFT。
在我的一个观点中,我尝试创建一个 NSBitMapImageRep,如下所示:
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()
}}
但是每次我尝试运行它时,我都会收到以下错误:
Inconsistent set of values to create NSBitmapImageRep fatal error: unexpectedly found nil while unwrapping an Optional value
我猜这是因为 bitmapDataPlanes 为零。但它是一个可选值,根据文档允许为 NULL。但是传递 NSNull() 不会编译。
谁能告诉我我必须通过什么? o_O
【问题讨论】:
标签: xcode macos swift nsbitmapimagerep