Note that there are some explanatory texts on larger screens.

plurals
  1. POAfter unarchiving my array, it suddenly contains NSRects instead of NSValues. How to retrieve the,
    primarykey
    data
    text
    <p>I wrapped <code>NSRect</code>s in <code>NSValue</code>s to get them into an NSMutableArray. I now want to add saving/loading capabilities to my app, so I thought I'd use <code>NSKeyedArchiver</code> and <code>NSKeyedUnarchiver</code>. <strong>Wrong!</strong> <code>NSKeyedArchiver cannot archive structs</code>. After a bit of searching I found a forum post from someone with the same problem. He solved it by using <code>NSArchiver</code> and <code>NSUnarchiver</code>. I implemented that, but once again, it didn't work. I can now encode it, but if I decode my array, I get back an array of <em><code>NSRect</code>s</em>! You can't even put them into an array! But I don't care, as long as I can get my rects back. But I can't, because <code>NSArray</code> only has methods for retrieving an object. A struct is not an object, so I can't retrieve my rects. How is this possible? How can I retrieve my archived rects?</p> <p>Part of MyDocument.m:</p> <pre><code>- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError { NSMutableArray *array = odview.ovals; return [NSArchiver archivedDataWithRootObject:array]; } - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { NSMutableArray *array = [NSUnarchiver unarchiveObjectWithData:data]; NSMutableArray *newOvals = [NSMutableArray array]; NSLog(@"array: %@", array); NSUInteger i, count = [array count]; for (i = 0; i &lt; count; i++) { NSRect rect = [array objectAtIndex:i]; // I can't do that because a struct is not an object! [newOvals addObject:[NSValue valueWithRect:rect]]; } odview.ovals = newOvals; return YES ; } </code></pre> <p><strong>How is is possible the wrapping NSValues disappear and how can I safely save and load my NSRects?</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload