Consistent error setting objective-c variables

@jfperusse

Exception invoking setValue:forKeyPath:, verify the arguments.

I seem to be getting this error frequently when trying to set properties that, I would guess, should be accessible using this api.

For example, I can’t set a background color on a view without getting this error (and yes, I was setting it using objc.color, not a Codea color).

I also can’t set the font size of the UITextView, again using actual UIFont and not Codea fonts.

And the same goes for setting the insets on the text view. I made a valid UIEdgeInsets, I think, at least I got no errors on it, but I couldn’t assign them to the text view without getting that error.

These seem like fairly normal properties that the api seems to suggest would be accessible, is there some reason they’re not? Is there some way to tell which properties will be accessible and which won’t?

Hi @UberGoober! Could you share a few sample code that give you the error please?

subs = vc.view.subviews
print(table.unpack(subs))

view = objc.UIView()
view.frame = objc.rect(180, 300, 400, 400)
view.backgroundColor = objc.color(200,200,33,255)

view2 = objc.UIView()
view2.frame = objc.rect(280, 600, 400, 400)
view2.backgroundColor = objc.color(200,200,33,255)

vc.view.addSubview_(view)
print(table.unpack(subs))

vc.view.addSubview_(view2)
print(table.unpack(subs))

—causes error twice:
Exception invoking setValue:forKeyPath:, verify the arguments.

I see nothing onscreen, and in addition to those exceptions, it’s clear from the print statements that the views are never added to the subviews of the main view.

@jfperusse any idea on how to resolve this? I also was unable to assign a UIEdgeInsets to the text view. I could initialize the UIEdgeInsets without any trouble, but when I tried to assign them to the text view I got the same error as above.

Hi @UberGoober. For the backgroundColor, since it is a UIColor and not a CGColor, you must assign a Codea Color type directly. I will update the objc.color documentation to clarify this.

As for the views not being added as subviews, the problem is that you are using . instead of : for calling addSubview_. Here’s the udpated code:

function setup()
    vc = objc.viewer
    subs = vc.view.subviews
    print(table.unpack(subs))
    
    view = objc.UIView()
    view.frame = objc.rect(180, 300, 400, 400)
    view.backgroundColor = color(200,200,33,255)
    
    view2 = objc.UIView()
    view2.frame = objc.rect(280, 600, 400, 400)
    view2.backgroundColor = color(200,200,33,255)
    
    vc.view:addSubview_(view)
    print(table.unpack(subs))
    
    vc.view:addSubview_(view2)
    print(table.unpack(subs))
end