Amazon.com Widgets Copying .h and .m files from project to project
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 30, 2014, 08:51:49 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 9
| | |-+  Copying .h and .m files from project to project
Pages: [1]   Go Down
Print
Author Topic: Copying .h and .m files from project to project  (Read 4060 times)
ljaygould
Newbie
*
Posts: 16






« on: February 03, 2012, 02:28:37 PM »

Okay...newbie here. Don't mind a little hazing...but here's a beef with the first problem in Ch. 9 (using the Kindle edition).

I explicitly re-typed the Complex.h and .m files...based on the files given in the book. But then you ask to #import Fraction.h.

You've done so well not throwing us past the deep end so far, but failed (i THINK) to provide a major skill, which is where to copy the previously written header files so that new programs can read them. I tried copying them to the root folder and while there are no errors showing in the editor I get a nasty runtime error until I comment every instance of the Fraction parts of this program!

What's REALLY annoying is that the editor seems to recognize the methods in Fraction.h and Fraction.m, providing correct case etc. for typing them in.

Here's what I get:


Build target Ch9prog1

Ld /Users/owner12/Library/Developer/Xcode/DerivedData/Ch9prog1-bkheznroiguwfgdroxtklpyppbjk/Build/Products/Debug/Ch9prog1 normal x86_64
    cd "/Users/owner12/Documents/Xcode files/Ch9prog1"
    setenv MACOSX_DEPLOYMENT_TARGET 10.7
    /Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/owner12/Library/Developer/Xcode/DerivedData/Ch9prog1-bkheznroiguwfgdroxtklpyppbjk/Build/Products/Debug -F/Users/owner12/Library/Developer/Xcode/DerivedData/Ch9prog1-bkheznroiguwfgdroxtklpyppbjk/Build/Products/Debug -filelist /Users/owner12/Library/Developer/Xcode/DerivedData/Ch9prog1-bkheznroiguwfgdroxtklpyppbjk/Build/Intermediates/Ch9prog1.build/Debug/Ch9prog1.build/Objects-normal/x86_64/Ch9prog1.LinkFileList -mmacosx-version-min=10.7 -fobjc-arc -framework Foundation -o /Users/owner12/Library/Developer/Xcode/DerivedData/Ch9prog1-bkheznroiguwfgdroxtklpyppbjk/Build/Products/Debug/Ch9prog1

Undefined symbols for architecture x86_64:
  "_OBJC_CLASS_$_Fraction", referenced from:
      objc-class-ref in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

HELP!!!!

Thanks,

Jay
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







« Reply #1 on: February 03, 2012, 03:04:48 PM »

If you want to copy one or more files from one project to another, the easiest way is to have both projects open in XCode and then to simply select the file or files to be copied and drag them into the appropriate place in the new project.   When the dialog appears, I suggest you check "Copy items..." so that a fresh copy of the file is made in the new project's folder.

Cheers,

Steve
Logged
ljaygould
Newbie
*
Posts: 16






« Reply #2 on: February 03, 2012, 11:17:52 PM »

Thanks so much. Clearly, it has to go through a registration process that is represented by the dialog box when you copy them that way.

Do you think - for the next person like me that comes along with this - you could print something about this process in the next edition? Thanks again. It seems so intuitive, but the requirement to have it copied to the project window rather than outside Xcode eluded me.

Jay
Logged
ljaygould
Newbie
*
Posts: 16






« Reply #3 on: February 05, 2012, 11:04:58 PM »

It would SEEM possible to use the Finder to move the files. They're only text files after all...right?

Here's the process I tried to follow: search for, say, Fraction.h and copy it into the folder of the new exercise. All seems well, and the compiler/editor recognizes the work, makes all the colors pretty and generates no errors...until runtime! then OOPS!!!!!

Same holds for using the Finder and then placing the headers into the project in Xcode...the dialog box asking how to handle the files comes up, and it seems all is well, again until runtime, when the build fails with error messages this newbie sees as from the bowels of Hell.

The process you mentioned, having both projects open and copying the files from one project into the other, is the ONLY way they work. There's obviously some kind of glue that binds these files into a project and that's the ONLY way it works.

This is all well and good, but where are we supposed to find this out in the documentation? I really appreciate your telling me how to do it, but in order to solve the next issue like this and then next...how would I have found out this if I didn't have an author as dedicated as Steve is to come back and work with us as we suffer through these exercises? In other words, grateful for the fish...but would like the fishing LESSON as well.
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







« Reply #4 on: February 06, 2012, 10:06:02 AM »

The best way to learn this stuff is to read the user guides.  There's one for XCode.  Next best approach is to Google what you're trying to do.

Cheers,

Steve
Logged
rickyshands
Newbie
*
Posts: 8






« Reply #5 on: May 18, 2012, 10:09:13 PM »

So I was reading this on Github:

http://git-scm.com/book/en/Git-Tools-Submodules

"It often happens that while working on one project, you need to use another project from within it. Perhaps it’s a library that a third party developed or that you’re developing separately and using in multiple parent projects. A common issue arises in these scenarios: you want to be able to treat the two projects as separate yet still be able to use one from within the other....
Git addresses this issue using submodules. Submodules allow you to keep a Git repository as a subdirectory of another Git repository. This lets you clone another repository into your project and keep your commits separate."

Here's the command line example:
$ git submodule add git://github.com/chneukirchen/rack.git rack

Of course it's not that simple. the article goes on, discussing such things as having a "detached HEAD," or working with "Subtree Merging"  as an alternative to using submodules.

Searching for how to accomplish this with Xcode 4,  I found this:

http://www.cocoanetics.com/2011/03/git-submodules-and-xcode-4/

"Previously when integrating existing library code with new projects I would have simply copied the necessary groups from from Xcode project to another. Then I would choose to copy the files to the new project to be sure that they got included in the source tree. Otherwise the project would not build for other people accessing the same source control management (SCM) server.
Now with Xcode 4 this technique no longer works. You simply cannot drag groups between workspaces. "

The post continues with a step by step procedure to add a submodule with git and integrate that with Xcode.
I'm going to try it out and I'll return with my thoughts.
Logged
rickyshands
Newbie
*
Posts: 8






« Reply #6 on: May 22, 2012, 05:21:22 PM »

Well, I've exhaustively tried to implement submodules on Xcode 4.3.2.  I've done just horrible things to my Xcode projects and my git repositories.  I've learned loads about git.  I've deleted things and started anew...I think 3 times...to no avail.  It just doesn't work. 

I'm going to try to use subtree merging with Xcode:
http://git-scm.com/book/en/Git-Tools-Subtree-Merging
...
Logged
rickyshands
Newbie
*
Posts: 8






« Reply #7 on: May 29, 2012, 06:54:01 PM »

Well I abandoned my attempt at subtree merging as well.

I read these two articles:

http://www.clintharris.net/2009/iphone-app-shared-libraries/
https://github.com/jverkoey/iOS-Framework#walkthrough

And finally I decided to just copy the files over.
Logged
plantboy
Newbie
*
Posts: 8






« Reply #8 on: July 12, 2012, 06:48:40 PM »

I eventually was able to add .h and .m files to my project, without clicking on the "Copy items into destination group's folder (if needed)" when adding the files. Therefore the files stayed at the original location and I just referenced them inside the project.

In order to include them, I could not figure out a good way to do it except for including the full path, such as this:


Code: (Objective-C)
#import "/Users/Rich/Documents/XCode Projects/Programming in Objective-C (4th Edition)/Classes/Fraction/Fraction.h"

I am sure there are better ways to do this, but I do not know how yet. For the time being, I like this approach, because it allows me to keep classes that this book keeps adding on to and re-using in one location, and I can use the code across all of the projects.
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.