Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > A good easy Cocoa book

A good easy Cocoa book (Page 2)
Thread Tools
PowerBookDude  (op)
Registered User
Join Date: Feb 2001
Location: USA
Status: Offline
Reply With Quote
May 9, 2002, 10:42 AM
 
Originally posted by Jeff Binder:
<STRONG>Or, you can do it by hand. Enter the code in a text file. You could do this with a command-line editor like pico, vi or emacs, or with BBEdit (make sure you choose UNIX style line endings), or you could just use PB. Once you've saved the file, open a terminal window, cd to the directory where you put your file, and type 'cc yourfile'. If you don't get any errors than it worked right. This creates a file called a.out which is your program. To run it, type './a.out'.</STRONG>
Oh, I can only run it from the Terminal? Not from Aqua or whatever? Dang. Could someone explain why I can only run it from the Terminal?


Thanks!
     
tinrib
Mac Elite
Join Date: Feb 2001
Location: Bristol, UK, living in Melbourne, Australia
Status: Offline
Reply With Quote
May 9, 2002, 10:58 AM
 
Originally posted by PowerBookDude:
<STRONG>

Oh, I can only run it from the Terminal? Not from Aqua or whatever? Dang. Could someone explain why I can only run it from the Terminal?


Thanks!</STRONG>
he said you can run it within project builder. presumably you are talking about running a command line app (such as hello world) which means you need a shell to run it unless you have something wrapped around the shell (project builder or a GUI (graphical user interface, pronounced gooey)).

so yeah, you can only run it from the terminal. but before long you'll be writing apps with a GUI, and hopefully my digital color meter. so accept it for now and persevere!
     
PowerBookDude  (op)
Registered User
Join Date: Feb 2001
Location: USA
Status: Offline
Reply With Quote
May 9, 2002, 11:10 AM
 
Originally posted by tinrib:
<STRONG>

he said you can run it within project builder. presumably you are talking about running a command line app (such as hello world) which means you need a shell to run it unless you have something wrapped around the shell (project builder or a GUI (graphical user interface, pronounced gooey)).

so yeah, you can only run it from the terminal. but before long you'll be writing apps with a GUI, and hopefully my digital color meter. so accept it for now and persevere!</STRONG>
I didn't totally understand the first part of what you said.

I should have been more clear. I was hoping to have an app with a GUI. So what I was asking is how can I can those three lines of text to display in an Aqua window?

Thanks!
     
Jeff Binder
Junior Member
Join Date: Feb 2002
Status: Offline
Reply With Quote
May 9, 2002, 05:23 PM
 
Programmers all have to start somewhere, and generally, that somewhere is the command-line. You need to know the basics of programming before you can start making GUI apps with Cocoa, so stick with it! You'll get there soon enough.
self = [[JeffBinder alloc] init];
     
PowerBookDude  (op)
Registered User
Join Date: Feb 2001
Location: USA
Status: Offline
Reply With Quote
May 9, 2002, 06:26 PM
 
Originally posted by Jeff Binder:
<STRONG> and type 'cc yourfile'. If you don't get any errors than it worked right. This creates a file called a.out which is your program. To run it, type './a.out'.</STRONG>
Thanks it worked!!!

I have an idea for the app I first want to make. I don't care if anyone has done this yet. I want to make a GUI app that it allows people to easily add and remove people from the ftpusers and ftproot files in the etc directory.

How hard would that app be to make?

Thanks!
     
hamiltondj
Forum Regular
Join Date: Aug 2000
Location: middlesex, nj, usa
Status: Offline
Reply With Quote
May 9, 2002, 07:45 PM
 
Originally posted by PowerBookDude:
<STRONG>

Thanks it worked!!!

I have an idea for the app I first want to make. I don't care if anyone has done this yet. I want to make a GUI app that it allows people to easily add and remove people from the ftpusers and ftproot files in the etc directory.

How hard would that app be to make?

Thanks!</STRONG>
Wow. This is actually deceptively simple. Deceptively because your going to have to understand how the unix file system works.

How well do you know unix? Buy a good unix book. I believe the one you may want is Unix Programming Environment by Pike and Kernighan.

In theory I think this is actually a good project for someone learning c.

A good learning tool is to write a program that reads from and writes to a file. I'm sure your C book will have you do this. Also pay very close attention on how to read from and write to files when you learn C.

Here's a tip - try and write this as a command line program first. Once that's done and it works as a command line, you should be able to start learing cocoa to wrap a gui around it (although this is a guess since I'm a Xwindows programmer learning cocoa)

From reading this thread and knowing where you've started, I think you can get a command line version of this working within a month.

Also, just to add my $0.02 - Learning C was the way to go. I also think its up to you if you want to learn C++ or Java next before cocoa. Personally, I would say get good at C then try for Obj-C and see if it clicks for you. If not, get a C++ book and learn the basics of C++ .
     
Marshall
Forum Regular
Join Date: Sep 2000
Status: Offline
Reply With Quote
May 9, 2002, 08:16 PM
 
Originally posted by tinrib:
<STRONG>if you wanted an idea for an app, a cocoa version of "Digital Color Meter" that shipped with OS 9 (in the Apple Extras folder) would be nice. </STRONG>
I don't have a copy of the OS 9 version here at the moment ... how does it differ from the OS X version?
     
PowerBookDude  (op)
Registered User
Join Date: Feb 2001
Location: USA
Status: Offline
Reply With Quote
May 9, 2002, 08:24 PM
 
Originally posted by hamiltondj:
<STRONG>

Wow. This is actually deceptively simple. Deceptively because your going to have to understand how the unix file system works.

How well do you know unix? Buy a good unix book. I believe the one you may want is Unix Programming Environment by Pike and Kernighan.
</STRONG>
Well I already read Learning the UNIX OS by O'Reilly and I am getting Learning UNIX for Mac OS X again by O'Reilly. Should that be enough? I already know how to alter the files via the command line I have done it.

Could you give me a basic idea of what the code would look like for this app?

Thanks!
     
hamiltondj
Forum Regular
Join Date: Aug 2000
Location: middlesex, nj, usa
Status: Offline
Reply With Quote
May 9, 2002, 09:37 PM
 
Originally posted by PowerBookDude:
<STRONG>

Well I already read Learning the UNIX OS by O'Reilly and I am getting Learning UNIX for Mac OS X again by O'Reilly. Should that be enough? I already know how to alter the files via the command line I have done it.

Could you give me a basic idea of what the code would look like for this app?

Thanks!</STRONG>
Please don't take this the wrong way - No.

I think there can be such a thing as too much help. Look at the chapters in your book about readin & writing files. They should be about 3/4 of the way through the book.

When you've learned how to do this, you'll understand that by showing you a "basic idea"I would have basically written the code for you.
     
PowerBookDude  (op)
Registered User
Join Date: Feb 2001
Location: USA
Status: Offline
Reply With Quote
May 9, 2002, 10:01 PM
 
Originally posted by hamiltondj:
<STRONG>

When you've learned how to do this, you'll understand that by showing you a "basic idea"I would have basically written the code for you.</STRONG>
I already understand now. That was dumb asking.

At least tell me on a scale of 1-10 how hard would it be with 10 being OMG you are a crazy fool for EVEN thinking about this!!!

Thanks!
     
hamiltondj
Forum Regular
Join Date: Aug 2000
Location: middlesex, nj, usa
Status: Offline
Reply With Quote
May 9, 2002, 10:41 PM
 
Originally posted by PowerBookDude:
<STRONG>

on a scale of 1-10 how hard would it be with 10 being OMG you are a crazy fool for EVEN thinking about this!!!

Thanks!</STRONG>
6 or 7

Difficult but very doable
     
PowerBookDude  (op)
Registered User
Join Date: Feb 2001
Location: USA
Status: Offline
Reply With Quote
May 10, 2002, 08:38 AM
 
Originally posted by hamiltondj:
<STRONG>

6 or 7

Difficult but very doable</STRONG>
Wow, 6 or 7 that was a little harder then expected. Let me guess the hardest part is reading and writing to the files huh?

Another thing I'd like to do is based off this O'Reilly article I read. It showed Mac OS X users how to activate SSI, PHP, CGI, SSL, regular password protection etc. So I want to make app that does that. That will really hard. Since in the article it said you need to tell it like for example what pages you want it to look for SSI and what not too. Like you can say Apache look for SSI only in .shtml and not .html stuff like that.

Thanks!
     
tinrib
Mac Elite
Join Date: Feb 2001
Location: Bristol, UK, living in Melbourne, Australia
Status: Offline
Reply With Quote
May 10, 2002, 12:47 PM
 
Originally posted by Marshall:
<STRONG>

I don't have a copy of the OS 9 version here at the moment ... how does it differ from the OS X version?</STRONG>
OSX version? where?

[edit: OMG! its there sitting in my utilities folder. I totally forgot that existed!]

[ 05-10-2002: Message edited by: tinrib ]
     
Jeff Binder
Junior Member
Join Date: Feb 2002
Status: Offline
Reply With Quote
May 10, 2002, 04:38 PM
 
One thing you should note is that this will not be an Aqua app- you're still writing unix stuff for now, not Cocoa. If you can write a CLI version of this, you will probably then know enough C to take a shot at learning Cocoa. Once you learn Cocoa you'll be able to make GUI apps.
self = [[JeffBinder alloc] init];
     
PowerBookDude  (op)
Registered User
Join Date: Feb 2001
Location: USA
Status: Offline
Reply With Quote
May 10, 2002, 05:03 PM
 
Originally posted by Jeff Binder:
<STRONG>One thing you should note is that this will not be an Aqua app- you're still writing unix stuff for now, not Cocoa. If you can write a CLI version of this, you will probably then know enough C to take a shot at learning Cocoa. Once you learn Cocoa you'll be able to make GUI apps.</STRONG>
I understand that.

However, could some explain why though you can't put a GUI on a C app?


And once again I want to say "Thanks'" for all your guys help. You guys have been quick to respond and very very helpful and very nice. Thank you.
     
skipjack
Dedicated MacNNer
Join Date: Oct 2000
Status: Offline
Reply With Quote
May 11, 2002, 12:43 AM
 
Originally posted by PowerBookDude:
<STRONG>
However, could some explain why though you can't put a GUI on a C app?
</STRONG>
You can, but it is not simple. Open Project Builder, select New Project, select Carbon Application, give it a name, and build the project. You get a window titled "Hello".

Now open the "Sources" folder in your project. You will see two files, main.h and main.c. You need all the stuff in those files just to put a window up that behaves the way you expect. I'm not an experienced programmer and when you asked about making a window, I tried finding an easy way you could modify the code, but I'll have to read the documentation more to find out how you could put something in the window.

I said to open a Carbon Application because that's in C.

Now do the same thing, except select Cocoa Application. You get a window titled "Window." Open the folder Other Sources and look at main.m. All the work is done in Interface Builder! Now double click on MainMenu.nib. That opens Interface Builder. IB will do the equivalent of writing all the stuff you saw in the Carbon window. You can write the code yourself and some of the Cocoa books will take you through that at some time.

As you saw, it took Project Builder a long time to show your window. Here's a hint: As soon as you make a new project, just build the empty project while you are thinking about what to write. Then most of the work will be done and when you put your code in, it will take a much shorter time to build your project. The compiler is building all the stuff in the "stdio.h" you include at the start of your program. (Press "Stop" on either the Carbon or Cocoa Application you built and run it again. You'll see!)

Need a break from coding? Try this for fun:

Cocoa Application you can make without writing code!

[ 05-11-2002: Message edited by: skipjack ]
     
conner
Fresh-Faced Recruit
Join Date: Jan 2002
Status: Offline
Reply With Quote
May 14, 2002, 06:18 AM
 
powerbook dude,

I left this thread a while ago... and you're still not totally taken over by programming books? Enough talking and get to coding!

forget about the GUI. forget about the ftp access. You have to learn to walk before you can run a marathon, and you're barely close to the crawling stage.

If you're going to be an OSX person, you have to learn UNIX. Not just "learn" it, but completely understand it. Understand everything you can. Learn about how it's evolved. Read about System V. Write essays on the differences between linux and BSD for your english class. Use every shell for a week and learn everything about them.

UNIX is your new home. Learn it. Learn it well.

While doing this, learn C. You will learn plain vanilla command line C. There will be no GUI apps in the near future. There have been some books mentioned here. Try those. Go to a local university library and look at the books yourself. See which style you like the best. For what I'm about to give you, you'll need many books for research.

I'm going to give you your first assignments. You'll have to learn *how* to do them on your own, doing your own research. You may have to write other programs and learn lots of new things before you do can do the next one. When you're done with them, you'll have passed the "basic" parts of programming:

1) Write a program to convert fahrenheit to celsuis. Make two versions, one to accept values at run time (ie: have user input fahenheit or celcius and output conversions). The other, have the user input a value of fahrenheit and save the celcius conversion to a file named cel.dat [ hint: learn functions, character input/output, file input/output]

2) Write a command line version of tic-tac-toe. It does not have to "redraw" the board in real time, ie: it can just scroll a new board after you do a move. [ hint: learn arrays]

3) Write a program to store numbers in an array. The program reads numbers from a file, seperated by commas.The array starts out with a size of 5. The array grows at application run time. [hint: learn pointers, dynamic memory allocation, dynamic arrays]

4) Do #3, but with a linked list. [hint: linked lists ]

5) Write a program to determine if an equation is balanced. that is, if there is a ")" to correspond for a "(". Example, (a+b(x+1)) is balanced, while (a+b)) is not. [ hint: stacks]

6) Write a recursive program to compute the power of a number. Example x^n. Do this with a time analysis of O(log N). [ hint: recursive functions, time analysis]

7) Write a program that reads in characters from a file, and puts them in a binary tree. The value for the characters are their ASCII values. [hints: trees]

8) Write a program to search through a file of 100 numbers that has a time complexity of O(log N)

9) Write two versions of quicksort (research what quicksort is). One that is recursive, and one that is not. Write a small paragraph about which one is better (faster). Use your program to sort an array. [ hint: quicksort, time analysis, stacks, recursive functions]

10) Write a program to compress files using Huffman Compression. [hints: trees, huffman compression].

If you want, you may email your code to me if you have problems.
[email protected]

Enough asking questions. Go get started. Learn by doing - it's the only way to become a decent programmer.
     
conner
Fresh-Faced Recruit
Join Date: Jan 2002
Status: Offline
Reply With Quote
May 14, 2002, 06:23 AM
 
ps: you may switch to C++ if you wish. I may even suggest it when you start #3 or 4.
     
PowerBookDude  (op)
Registered User
Join Date: Feb 2001
Location: USA
Status: Offline
Reply With Quote
May 14, 2002, 10:53 AM
 
Originally posted by conner:
<STRONG>Enough talking and get to coding!
</STRONG>
I haven't learned enough yet to code. I just got my book a weekk ago and I have only read like 50 pages. The only thing I could make is an app that says Hello or the alike.

I may need to ask a question later I don't understand the current chapter but we'll see.

Thanks!
     
baron
Fresh-Faced Recruit
Join Date: May 2002
Status: Offline
Reply With Quote
May 17, 2002, 12:23 PM
 
I've been following this thread for a while myself and I can't believe the restraint and patience that you people have. All the inane questions being asked by PowerBookDude is driving me nuts!

PowerBookDude, I would suggest you take Conner's advice and don't ask any more questions until you've done some actual work. Keep reading, yes, but you have to start coding and making mistakes. And when you make mistakes and the program doesn't work correctly, you have to try to figure out why YOURSELF! If, after a week or two of banging your head against the wall, you still can't figure something out, then it's OK to ask questions. But you can't learn to program just by reading and asking a bazillion questions. You have to actually sit down for hours on end with your favorite editor and code. That is the ONLY way.
     
 
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 05:57 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,