Where To Save Class Files In Application?


#1

Does it matter where in the application file we save our class files? Will they function the same way if they are in the same file as main.m? I also noticed some sample code in the documentation that has class files in a classes folder. To do this do I just make a new folder in the application file called classes and save it there? I tried a few things and wasn’t getting the results I wanted that is I’d make the classes folder but the new class file wouldn’t be in the folder. This as been bugging me a little bit as I’ve been moving on past this chapter.


#2

Xcode will find and compile them regardless. (But, try not to move them once they’ve been created – Xcode can lose track of where they are.)


#3

[quote=“Mr. Hillegass”]But, try not to move them once they’ve been created – Xcode can lose track of where they are.[/quote]Are you speaking of moving them via the Finder or in the Navigation pane of Xcode. I used the Navigation Pane method before I read your post. It didn’t solve the “Not found problem” but that was caused by my stupidly using import [size=150]<[/size]Person.h[size=150]>[/size] instead of import [size=150]"[/size]Person.h[size=150]"[/size] :unamused: :blush:


#4

I’m saying: “If you add a file to an Xcode project and move it in Finder, Xcode will loose track of it.”


#5

You can put all your classes in your main.m file if you want, but that would be total madness and I would only do it for small toy projects.

When it comes to moving your files around (a legitimate thing to do), I would be very careful:

  • Remove the files from Xcode, being very careful not to clobber them;
  • Move them to where you want them using the Finder; and
  • Add them back to your project in Xcode.

#6

I guess I misunderstood the original question, but I was thinking the original poster meant where should the files reside in the directory structure, i.e. in which folder, rather than in which files should a class definition go.

In any event, that’s my question too. Here’s what I mean: In the BMITime example, when I look at the Navigator pane on the left hand side of the Xcode window, my Person.h and Person.m files landed within the BMITime project, immediately under the blue icon with title BMITime, but not inside the yellow folder called BMITime.

But, when I went to do the stocks challenge, my StockHolding.h and StockHolding.m files landed within the folder called Stocks, that is, within the yellow icon, an entire level deeper than where the new class files landed in the BMI exercise.

So I’m wondering, which of these is the correct location, and do I need to click somewhere specific before I create the new class in order for the files to land in an appropriate place?

Thanks!