I am trying to use the code that follows to get the foreground color of an NSTextView. Unfortunately I get a runtime error that must be related with the involved color spaces. How can I fix m
if let textStorage = textView.textStorage {
let rowObj = textStorage.paragraphs[row]
let range = NSMakeRange(0, rowObj.string.characters.count)
colorOrRowBeforeSelection = rowObj.foregroundColor!
if(rowObj.foregroundColor != nil) {
let r = rowObj.foregroundColor!.redComponent
let g = rowObj.foregroundColor!.greenComponent
let b = rowObj.foregroundColor!.blueComponent
} else {
Log.e("cannot get foreground color components")
}
} else {
Log.e("textStorage = nil")
}
I get the following runtime error:
[General] *** invalid number of components for colorspace in initWithColorSpace:components:count:
I made it working with the following:
EDIT: I made a fix on the memory handling, now the code works except from the fact the it turns what should be white (in the grey color space) into yellow... hope someone can fix that.