Collection element of type 'double' is not an Objective-C object
Asked Answered
E

2

10

The inY property gives an error. What is the correct syntax?

UIButton *optionButton = [UIButton buttonWithType:UIButtonTypeCustom];
NSObject* anim = @{@"target": target, @"inY": infoView.frame.size.height-100, @"outY": @800};

Tried creating a variable with it as done with optionButton but it doesn't seem to work. I presume I need to cast it as something the collection can understand.

Excepting answered 31/3, 2014 at 9:28 Comment(0)
C
15

infoView.frame.size.height-100 is a float. You can't cast it, you need to box it in an NSNumber (similar to what you've done with the 800 value for outY):

@(infoView.frame.size.height-100)
Candra answered 31/3, 2014 at 9:30 Comment(1)
Thanks! was trying with {} but () was exactly what I needed.Excepting
B
2

Try [NSNumber numberWithDouble:xxx]

This will then create an Objective-C NSNumber object which contains the double.

Bubb answered 31/3, 2014 at 9:33 Comment(2)
@(xxx) does exactly the same, and is more modern, concise and readable.Pesade
@() @[] @{} @## is the recommended literal syntax that you should useForeleg

© 2022 - 2024 — McMap. All rights reserved.