Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set a value for CGRect.frame.size from a NSDictionary

I generate a dictionary from a JSON string, and one of the value of the dictionary aims to be used as the height of a WebView object.

NSDictionary *dic = [jsonParser objectWithString:response];
CGFloat *height = [dic valueForKey:@"intHeightPixels"];
CGRect frame = webView.frame;
frame.size.height = height;
webView.frame = frame;

In line 2 I get the following error:

Initializing 'CGFloat' (aka float) with an expression of incompatible type 'id'.

I'm newbie in Objective C I don't know if this has something go see with pointers, casting, please give me some light.

like image 524
R01010010 Avatar asked Mar 08 '26 00:03

R01010010


2 Answers

you can take particular value in string i.e,

NSString *str=[arr valueForKey:@"location"];
CGRect rect9 = CGRectFromString(str);

This will convert to CGRect so that you can use it in the place of Frame

like image 190
Nethravathi L Avatar answered Mar 10 '26 13:03

Nethravathi L


You might want to try CGFloat *height = [[dic valueForKey:@"intHeightPixels"] floatValue]; In dictionaries there is only object (here it's a NSNumber)

like image 41
Aymarick Avatar answered Mar 10 '26 13:03

Aymarick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!