NSInvalidArgumentException', reason: '-[__NSArrayM isValid] - objective-c

can anyone tell me what may be the reason of crash.
Application Specific Information:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isValid]: unrecognized selector sent to instance 0x3f4a80'

You sent the selector isValid to an array, which doesn't respond to that message. That's all that can be said without seeing the code.

Here is my case,
to solve it:
Add -all_load to the other linker flags in your build settings.
-all_load forces the linker to load all object files from every archive it sees, even those without Objective-C code.
more description:
The "selector not recognized" runtime exception occurs due to an issue between the implementation of standard UNIX static libraries, the linker and the dynamic nature of Objective-C. Objective-C does not define linker symbols for each function (or method, in Objective-C) - instead, linker symbols are only generated for each class. If you extend a pre-existing class with categories, the linker does not know to associate the object code of the core class implementation and the category implementation. This prevents objects created in the resulting application from responding to a selector that is defined in the category.
To resolve this issue, the target linking against the static library must pass the -ObjC option to the linker. This flag causes the linker to load every object file in the library that defines an Objective-C class or category. While this option will typically result in a larger executable (due to additional object code loaded into the application), it will allow the successful creation of effective Objective-C static libraries that contain categories on existing classes. Follow these steps to pass -ObjC to the linker:
In Xcode, double-click the target's name under "Targets"
in the Project window.Choose the Build pane from the ensuing Info window.
Scroll down to the Other Linker Flags build setting under the Linking collection and set its value to -ObjC.

Related

Using categories in iOS 8 frameworks

I am trying to share some code between an app and an extension, using a framework. Mostly this works, but I have several categories that do not seem to load correctly in the extension. For example, I have a category on NSString to reverse the target string, but when I try to use that selector within the extension my code traps with an "unrecognized selector" exception. I tried adding the "-all_load" linker flag, first to just the framework, and then to the extension, to try and force load all the classes implemented in the framework, but this does not seem to work.
Any suggestions would be most welcome...
-David
If I remember correctly you need to set -ObjC in other linker flags in the parent project that is using your library/framework. The -all_load was being used to fix a bug in the -ObjC one, this is not needed anymore.

Some Parse methods not working in iOS SDK

I added the Parse SDK today (1.2.15) to an existing project which targets iOS7 and is built in Xcode5. I followed the instructions on https://parse.com/apps/quickstart#ios/native/existing exactly. Some things work, like creating and saving a PFObject. Certain functions however cannot be found by the compiler. For instance [PFUser enableAutomaticUser]; generates the error
AppDelegate.m:21:13: No known class method for selector 'enableAutomaticUser'
and [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions]; generates the error
AppDelegate.m:20:6: Use of undeclared identifier 'PFAnalytics'
Are the docs out of date and have these methods moved? I have tried restarting Xcode and cleaning my project. I can see the PFAnalytics.h file if I expand Parse.Framework in Xcode, and when I look at PFUser.h I can see a declaration of enableAutomaticUser;. Why can Xcode see some Parse classes and methods but not others?
My problem was that Framework Search Paths in Build Settings contained two directories, and one was invalid, resulting in this very strange behavior where some methods in Parse worked and others didn't.

add categories in xcode4

I copied the timeAgo category for NSDate in XCODE4, but i get the following runtime error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDate timeAgo]: unrecognized selector sent to instance 0x17e000'
I read in other posts i need to add a linking flag, which I did as follows:
But its still not working. What am I missing to use third party categories?
I don't think you ought to mess with the linkers, at least not there. Wherever you got that category from may have mentioned that the file you put that in needs to be compiled, which you check by going to your project settings -> Build Phases -> Compile Sources. Make sure the category's .m file is in there.

Unrecognized selector calling category method in static iOS library

I am using some third party software to aid in writing an iPad application using Xcode 4.3.2. The software is open source and is usually set up so its code will be compiled along with whatever code the developer writes for the application. Because I was using the software in numerous places, I decided to build it as a static library for the iOS simulator.
I was able to build the library, and convert one application to link to that library instead of compiling the original source code. However, when I go to run the application on the simulator, I get an error that says, unrecognized selector sent to instance.
I have verified that the program is successfully using portions of the static library. However, there is one piece of code that tries to call a method on an object, and that where the failure occurs. The method being called is not actually defined in the interface of that object. Rather it is provided in an additional module that defines a category for that object's class. The header file for that module is properly included and the compiler should have been able to find the category method and apply it to the object, yet at run time, the error mentioned above occurs.
I used the 'nm' command to verify that the category method exists in the static library. Here is an example of the output:
nm libStaticLibrary.a | grep categoryMethod
00000130 t -[SomeClass(Category) categoryMethod:]
0000354c s -[SomeClass(Category) categoryMethod:].eh
What ideas do people have about how this library can be made to work correctly with the desired application?
Your 3rd party framework is probable using a category on a existing (apple) class. But to load/find the category you need to add the -ObjC flag in the build settings under Other Linker Flags
Pfitz answer is great, but this will cause the compiler to load a bunch of unused binaries to your project which is not what you want. Please refer to this answer to know why https://stackoverflow.com/a/22264650/1363997
Here is the best solution:
1) select your project target from the left panel (the folders navigator)
2) select "Build Phases" tap
3) expand "Compile Sources" cell
4) hit the plus button at the bottom and then add your category's .m file
Done!
Note: you have to search for the file by navigating through the folder by your self, don't type the file's name in the search field

Objective-C category is not loaded - How to debug this

I have two projects which the RestKit framework.
One project works without problems but another project fails, as soon as the RestKit framework is used.
I found out that the failing code is this:
return [anNSString MD5];
The MD5 method is a category method and is imported like this:
#import "NSString+MD5.h"
However, in one project, I keep getting the following error:
-[__NSCFString MD5]: unrecognized selector sent to instance 0x88a3390
I understand the basics of categories, and that they can be loaded at runtime, but I don't see why the category does not get loaded in this case.
These are the files on github: NSString+MD5.m, NSString+MD5.h,
Make sure you have the -ObjC flag enabled. Or it will not link categories in a static library.
Objective-C categories in static library
It's not enough to just include the header file. You also need to compile and link the .m file in your project.