3

I'm making an iPhone game and would like to use YAML for the data files. Thanks to this question I went ahead and got the syck library. I managed to compile the library with xCode and to import the framework into my project[1]. My code successfully imports the header files, and xCode even finds the completions, but when I try to run the following code, I get an invalid selector exception:

NSMutableArray *arr = [[NSMutableArray arrayWithCapacity:4] retain];

[arr addObject:@"FOO BAR BAZ QUUX"];
[arr addObject:@"FOO BAR BAZ QUUX"];
[arr addObject:@"FOO BAR BAZ QUUX"];
[arr addObject:@"FOO BAR BAZ QUUX"];

NSLog([arr yamlDescriptionWithIndent:0]);
[arr release];

This is the error I get:

2013-04-01 23:27:50.530 PhaseWrath[13910:207] -[__NSArrayM yamlDescriptionWithIndent:]: unrecognized selector sent to instance 0x5548a30
2013-04-01 23:27:50.533 PhaseWrath[13910:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM yamlDescriptionWithIndent:]: unrecognized selector sent to instance 0x5548a30'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x0145f5a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x015b3313 objc_exception_throw + 44
    2   CoreFoundation                      0x014610bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x013d0966 ___forwarding___ + 966
    4   CoreFoundation                      0x013d0522 _CF_forwarding_prep_0 + 50
    5   PhaseWrath                          0x00005e85 +[Skeleton initialize] + 517
    6   libobjc.A.dylib                     0x015b3d9b _class_initialize + 380
    7   libobjc.A.dylib                     0x015bb73f prepareForMethodLookup + 73
...

It seems like the header files get parsed, but something goes wrong at the point where the library code would actually be linked... any ideas? I'm quite new to xCode and developing for the iPhone in general.

[1] If I did something wrong it probably was at this step.

Community
  • 1
  • 1
Claudiu
  • 224,032
  • 165
  • 485
  • 680

1 Answers1

1

Are you passing the -ObjC and -all_load linker flags in your build settings? Those are required when linking to libraries that include Objective-C categories (which is what Syck uses to add methods to NSArray and other builtin classes). See these for details:

Community
  • 1
  • 1
Stuart M
  • 11,458
  • 6
  • 45
  • 59
  • I will check it out when I get home tonight. That seems promising. I'm just using whatever the default settings are... I wonder why those wouldn't be set by default? – Claudiu Apr 02 '13 at 15:01
  • yep, i just checked and those flags are already there... any other thoughts? – Claudiu Apr 10 '13 at 02:02
  • I also can't use the function `yaml_parse`, which is not a category, so this doesn't seem to be a category-related issue... – Claudiu Apr 10 '13 at 02:13
  • Try the debugging tip described on http://www.fruitstandsoftware.com/blog/2012/08/quick-and-easy-debugging-of-unrecognized-selector-sent-to-instance/ – Stuart M Apr 10 '13 at 04:02
  • I know where it was sent from, that's not the issue. Again, forget I ever mentioned selectors. I have a C function in the YAML library, `yaml_parse`, and although the header files are included, the linker can't find the C function. Why not? – Claudiu Apr 10 '13 at 05:33
  • Can you post your complete Xcode build log somewhere, in a Gist perhaps? – Stuart M Apr 10 '13 at 05:42
  • Sure, next time I'm working on it I'll do that. Thanks for still looking into this. – Claudiu Apr 10 '13 at 14:55