What is my "Target" and how do I add a file to it for unit testing?
I'm trying to add my parser.m file to the target of my unit test (or, of my unit test file?), but I have no idea how.
Here's an example of a page that indicates the necessity of using the target:
Undefined symbols for architecture i386 "_OBJC_CLASS_$_Appirater"
...and here's part of an answer from that page:
I think, that you only added files to project, but not to target. Click on Appirater.m file in Project Navigator and set checkbox near to your target name in Target membership of File Inspector.
What I don't get from that answer is, "what checkbox?". Also, how do I know my target name? Where do I find 'Target membership'?
In Xcode, a target is usually an app - the app which you are creating! Occasionally it is a library or framework. (You can create other kinds of targets but don't worry about that.)
You can use the File Inspector to add a file to a target, or remove a file from a target, or just check whether a file is a member of a target. Simply open a .m
file or a resource file (like an image or xib) in the editor pane, then select the File Inspector in the right-hand pane of the Xcode window and find the “Target Membership” section of the inspector. Check or uncheck the box next to your target. (You usually do not want to add .h
files to targets.) Here's a demonstration:
If you have multiple targets in the project, each target appears in the “Target Membership” section. Each source file can be a member of any combination of the targets, depending on your needs. For example, if you are creating separate iPhone and iPad apps (instead of a universal app) which share most of their code and resources, you can create a project with two targets. One target is the iPhone app and the other target is the iPad app. You add the common source files to both targets. You add the iPhone-specific .m
files and resource files to the iPhone app target only. You add the iPad-specific .m
files and resource files to the iPad app target only.