Problem saving CGRect in plist

I am trying to save an array containing values CGRect. I know that plists are not compatible with the type CGRect, so I changed my code a bit, and now I save NSNumberinstead of saving the rect value - I divide the rectangle value into four values: x, y, width, height.

[myArray1 addObject:[NSNumber numberWithFloat:CGRectGetMinX(rawRect)]];
[myArray1 addObject:[NSNumber numberWithFloat:CGRectGetMinY(rawRect)]];
[myArray1 addObject:[NSNumber numberWithFloat:CGRectGetWidth(rawRect)]];
[myArray1 addObject:[NSNumber numberWithFloat:CGRectGetHeight(rawRect)]];

Now it myArray1contains only NSNumber, and I am trying to store these values ​​in a plist, but I can not load the values ​​back. Can someone fix me if I have something wrong with my code?

Thanks in advance; I look forward to your valuable information.

+3
source share
2 answers
CGRect rect  = CGRectMake(0, 0, 320.0f, 480.0f);
//you need to translate the rect into a compatible "Plist" object such as NSString
//luckily, there is a method for that

[rectArray addObject:NSStringFromRect(rect)];

//save into a plist


...

when retrieving this value

CGRect rect = CGRectFromString([rectArray objectAtIndex:0]);
+17
source

. , , . , , , .

johnoodles, , , , , plist, . , , , , , , , .

0

All Articles