Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
854 views
in Technique[技术] by (71.8m points)

xcode - 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'?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

add MyObject.m to addToTargetDemo target

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...