Bugs and errors can be frustrating to fix. Unfortunately, bugs are going to happen and you will see errors from time to time. Often errors appear because of the smallest detail.
One such error that popped up when I was building a project was the “Apple mach-o linker error”. It took me about an hour to eventually track it down. Here is what you will see on screen with this error:
What you see above is the error down the left navigation pane in Xcode and in the centre view you see more details which looks like just a big bunch of random characters. I have circled the main part which referrers to the RecipeAddiewController*. Looking at the project, I do actually have .h and .m files with that name.
To get rid of the error in this situation, I simply need to select the RecipeAddViewController.m file and in the inspector on the right, I need to look for Target Membership and make sure the box is checked. This links to the file to the code and resolves this particular problem.
This particular problem can arise when importing code into a project you have already created. For example, you might drag in some code that you found on GitHub, lets say a wrapper class for the Foursquare API. When you drag code in to the project, a box pops up like seen below. When bringing code in, it’s important to make sure you check the Add to targets box. If you don’t do this then problems might arise.
What I have found with testing is that you can have files in your project that are not linked and it also appears to be OK to import them in to other files in your project. However, if you start to create an object from a class that isn’t linked, then you get this error… so alloc/init an object that isn’t added to the target then you’ll see this error message.
As mentioned above, the fix is to select the .m of the file mentioned in the error and check the target membership section area.
Although the above will help you fix this error when you come across it, I haven’t included every single reason that this error might occur because I am sure there are a number of reasons why it can appear.
Just as a couple of examples, some cases relate to adding code for CoreData and forgetting to link in the CoreDate.framework to your project. It can also happen when you try link to a library that isn’t present in an updated SDK.
When in doubt, do a quick scan of the error and look for something that is unique. If you find something unique, like I did with the RecipeAddViewController then take a look at that and see what might be causing the problem. Perhaps it is just a simple matter of linking the file to the project, or perhaps there is something else going on there.
*RecipeAddViewController I believe comes from a sample Apple project I was working on and somehow, unlinked the file. I just wanted to be transparent with that so you are aware of what and how I tested.
Leave a Reply
You must be logged in to post a comment.