Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

SRossi

macrumors regular
Original poster
May 27, 2009
202
0
Glasgow, Scotland
Hey all,

Was looking through Programming in Objective-C 2.0 by Stephen Kochan although I had already done Aaron Hillegass' book i wanted to know more about objective c.

But right the question, as I was going through the book I found it tedious to code, then compile and then run, so i thought ... what if I make a simple app exactly like ZIPspector for Aaron's book (chapter 34), which takes the .m file and compiles it and runs it just as it was opened.

I've thought that this could run into a massive application but right now I would like some help as into how you would do this.

Obviously I would run an NSTask but what do I connect it to in the launch path of the task? Would it be /sbin/gcc?

Also after that bit is dealt with how would I set the arguments for the compiler? Right now I would only like it to import the Foundation.h file (keep it simple the now).

All help will be deeply appreciated as usual :).

Stephen :cool:
 

HiRez

macrumors 603
Jan 6, 2004
6,250
2,576
Western US
Maybe I'm not understanding what you want, but why can't you use Xcode to organize your project and compile? It's two key presses to compile only, or compile and run...
 

Cinder6

macrumors 6502a
Jul 9, 2009
509
50
I think this project will be more complex than you expect. For simple things (e.g. single source programs), it's easy, but when it comes to larger projects, you need some way of telling the application how it's organized, so it can follow the correct build order. And if you have to supply that, you might as well create a Makefile. And if you have a Makefile, then all you need to do is type 'make' in the Terminal, thus rendering an application like this redundant.

Unless I'm missing something, and you want to do what Xcode already does?
 

SRossi

macrumors regular
Original poster
May 27, 2009
202
0
Glasgow, Scotland
Right yes I do understand that using Xcode is the best idea, but not when your projects are only one file and maybe less than 200 lines long. Because for each application you have to create a new project, and do it that way.

I was creating the files in VIM and then compiling and running from the terminal but i would like it so that i could write an application that compiled and ran it as the file was opened using the Open File option in the menu (exactly like ZIPspector in Aarons book). See what I am meaning now? I know exactly how it will look and feel and should cut down the time of compiling and running the .m file, it will also give me a bit more experience as well.

Thanks,

Stephen
 

skochan

macrumors regular
Apr 1, 2006
150
0
California
I was creating the files in VIM and then compiling and running from the terminal...

Stephen,

I have also edited, compiled, and tested many of the programs in the book in a Terminal window. In those cases, I would start vi on the file I wanted to test, type it in, save it, and then compile and run it from inside vi using the shell escape :!. For example, if I were testing prog7-1.m, I would type the following into vi:

Code:
:!c %

where % gets replaced by vi with the current filename and c is a shell script that looks like this:

Code:
gcc -framework foundation -std=c99 $1 && ./a.out

The nice part is that I stay in vi, so it's easy to iterate; fix errors, save, then type :!! to rerun the last shell command. I don't know if this is the elegant solution you're looking for, but it worked for me!

Cheers,

Steve Kochan
 

SRossi

macrumors regular
Original poster
May 27, 2009
202
0
Glasgow, Scotland
Stephen,

I have also edited, compiled, and tested many of the programs in the book in a Terminal window. In those cases, I would start vi on the file I wanted to test, type it in, save it, and then compile and run it from inside vi using the shell escape :!. For example, if I were testing prog7-1.m, I would type the following into vi:

Code:
:!c %

Ahh what a brilliant command :cool: never knew that you could compile and run from within vi.

But can I just stress, right now this is only for extremely simple applications that will only include the Foundation.h file. It will not contain more than one .m file the now, perhaps in the coming months I perhaps will try and build it to run multiple arguments and files but my question still stands, what launch path should I use for the NSTask would it only be /sbin/gcc?

Because thats really all I need to know the now for me to continue.

Thanks for all your helps and tips so far :).

Stephen
 

mslide

macrumors 6502a
Sep 17, 2007
707
2
It sounds like you're trying to re-invent the wheel here. There are lots of build systems out there that make compiling your code easier.

What I would do is create a generic Makefile that will build any .m files it finds in the current directory and create an executable that is the same name as the first file it finds.
 

Cinder6

macrumors 6502a
Jul 9, 2009
509
50
Since it seems you want to create this thing regardless...

The launch path would be the path to the executable. I'm not sure what's up, but my gcc is in /usr/bin, not /sbin; double-check yours. The arguments would be the switch to link in the Foundation framework, plus your source code file that you get with the "open" dialog (you'll again want the full path). Then you have to decide where the executable will go--I'd recommend the same place the source file is located. Just remember you need the -o switch for that.

Hope that helps.
 

SRossi

macrumors regular
Original poster
May 27, 2009
202
0
Glasgow, Scotland
Right most of the coding has been done (think there are no problems) but one final last question the now, what would be the file type for the application as you have to insert the file type into the UTI cell for the target. What should I put in this cell to accept .m files?

Thanks,

Stephen
 

SRossi

macrumors regular
Original poster
May 27, 2009
202
0
Glasgow, Scotland
No choice you have to specify a file type Aaron uses "com.pkware.zip-archive" that how I am unsure what file types I can use.

Thanks Stephen

EDIT: After looking at the Developer files all I think I need to do is enter "com.mine.m". Feel free to correct me though.

EDIT 2:And Cinder has just corrected me thanks for that link ;) sometimes I think Apple's documentation just is not enough.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.