Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9025163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:12:16+00:00 2026-06-16T06:12:16+00:00

I found the answer after I set the bounty. If somebody has some useful

  • 0

I found the answer after I set the bounty. If somebody has some useful comments on my approach (I don’t know if it is the ‘right’ solution) he/she can have the bounty. If you’re going to downvote my question, please leve a comment so I can improve future questions.

I’m currently learning Objective-C with the book Cocoa Programming For Mac OS X and it introduces archiving in chapter 10. I (AFAIK) did exactly what the author wants me to do, but when opening a file and thus unarchiving it the app crashes on the line:

array = [NSKeyedUnarchiver unarchiveObjectWithData:data];

It says GDB received signal: EXC_BAD_ACCESS. I have only encountered this when accessing an array slot that is out of bounds, and I believe I am not doing that. My best guess is that something behind the Cocoa scenes goes wrong, indirectly caused by me. What could this be?
As I said I am currently learning Objective-C (but I know Java), so don’t expect me to know every obscure language feature.

The file opening method (MyDocument.m):

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
    NSMutableArray *array = nil;
    NSLog(@"data is %@", data);

    @try {
        array = [NSKeyedUnarchiver unarchiveObjectWithData:data]; // line of the EXC_BAD_ACCESS
    }
    @catch (NSException * e) {
        if (outError) {
            NSDictionary *d = [NSDictionary dictionaryWithObject:@"The data is corrupted." forKey:NSLocalizedFailureReasonErrorKey];
            *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:d];
        }
        return NO;
    }
    [self setEmployees:array];
    return YES;
}

The file saving method (still MyDocument.m):

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
    [[tv window] endEditingFor:nil]; // tv is my IBOutlet to an NSTableView

    return [NSKeyedArchiver archivedDataWithRootObject:employees];
}

This is the stack trace (Thanks, H2CO3):

(gdb) bt
#0  0x00007fff858da104 in objc_msgSend_vtable13 ()
#1  0x00007fff858dcff5 in objc_getProperty ()
#2  0x00000001000022cf in -[Person name] (self=0x1001d4480, _cmd=0x7fff89d1a790) at /Users/mauritsfriedrichkoelmans/Desktop/RaiseMan1/Person.m:14
#3  0x00007fff86e79674 in -[NSObject(NSKeyValueCoding) valueForKey:] ()
#4  0x00007fff86e7cfb8 in -[NSObject(NSKeyValueCoding) valueForKeyPath:] ()
#5  0x00007fff897e10df in -[NSBinder valueForBinding:atIndex:resolveMarkersToPlaceholders:] ()
#6  0x00007fff89682aa2 in -[NSValueBinder _adjustObject:mode:observedController:observedKeyPath:context:editableState:adjustState:] ()
#7  0x00007fff897e0e75 in -[NSValueBinder updateTableColumnDataCell:forDisplayAtIndex:] ()
#8  0x00007fff897e0d83 in -[NSTextValueBinder updateTableColumnDataCell:forDisplayAtIndex:] ()
#9  0x00007fff897e0d30 in -[_NSBindingAdaptor tableColumn:willDisplayCell:row:] ()
#10 0x00007fff896cab00 in -[NSTableView preparedCellAtColumn:row:] ()
#11 0x00007fff896ca306 in -[NSTableView _dirtyVisibleCellsForKeyStateChange] ()
#12 0x00007fff896c9e96 in -[NSTableView _windowChangedKeyState] ()
#13 0x00007fff88ba0d3e in CFArrayApplyFunction ()
#14 0x00007fff89611478 in -[NSView _windowChangedKeyState] ()
#15 0x00007fff88ba0d3e in CFArrayApplyFunction ()
#16 0x00007fff89611478 in -[NSView _windowChangedKeyState] ()
#17 0x00007fff88ba0d3e in CFArrayApplyFunction ()
#18 0x00007fff89611478 in -[NSView _windowChangedKeyState] ()
#19 0x00007fff88ba0d3e in CFArrayApplyFunction ()
#20 0x00007fff89611478 in -[NSView _windowChangedKeyState] ()
#21 0x00007fff896c991f in -[NSFrameView _windowChangedKeyState] ()
#22 0x00007fff89611171 in -[NSWindow _setFrameNeedsDisplay:] ()
#23 0x00007fff8960f1d8 in -[NSWindow _makeKeyRegardlessOfVisibility] ()
#24 0x00007fff8960f13e in -[NSWindow makeKeyAndOrderFront:] ()
#25 0x00007fff89814401 in -[NSWindowController showWindow:] ()
#26 0x00007fff897e5c5c in -[NSDocument showWindows] ()
#27 0x00007fff899539c1 in -[NSDocumentController openDocumentWithContentsOfURL:display:error:] ()
#28 0x00007fff89953072 in -[NSDocumentController _openDocumentsWithContentsOfURLs:display:presentErrors:] ()
#29 0x00007fff8976eeda in -[NSApplication sendAction:to:from:] ()
#30 0x00007fff8979346a in -[NSMenuItem _corePerformAction] ()
#31 0x00007fff897931d4 in -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] ()
#32 0x00007fff89778e45 in -[NSMenu performKeyEquivalent:] ()
#33 0x00007fff89777bed in -[NSApplication _handleKeyEquivalent:] ()
#34 0x00007fff896486b9 in -[NSApplication sendEvent:] ()
#35 0x00007fff895df6de in -[NSApplication run] ()
#36 0x00007fff895d83b0 in NSApplicationMain ()
#37 0x0000000100001e9b in main (argc=1, argv=0x7fff5fbff660) at /Users/mauritsfriedrichkoelmans/Desktop/RaiseMan1/main.m:13
(gdb) 

The data object is not nil, NSLog()ed it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:12:17+00:00Added an answer on June 16, 2026 at 6:12 am

    I solved it myself!

    In the book, the initWithCoder: method of the Person class (the array I try to unarchive is filled with instances of that class) looks like this:

    - (id)initWithCoder:(NSCoder *)coder {
        [super init];
        name = [coder decodeObjectForKey:@"name"];
        expectedRaise = [coder decodeFloatForKey:@"expectedRaise"];
        return self;
    }
    

    But it had to be:

    - (id)initWithCoder:(NSCoder *)coder {
        [super init];
        self.name = [coder decodeObjectForKey:@"name"];
        self.expectedRaise = [coder decodeFloatForKey:@"expectedRaise"];
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
I have found this answer really useful. It helps me plot network/graphs and select
Update: I've found a partial solution in this answer here , by adding the
After figuring out the answer to my previous question I have found the cause
I spent some time searching for an answer to this and found plenty of
After reading related questions #1 , #2 I still haven't found an answer to
Found the answer!! Found the answer after a long break from looking at it!
FOUND THE ANSWER MYSELF, see below... I'd like to have a very simple user
I found this answer to this question https://stackoverflow.com/a/7244888/1473523 , but in my situation am
I found this answer and it sounds like almost exactly what I'm doing. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.