PDA

View Full Version : UIKit, XCode, and Obj C help: I dont understand.




Duke Leto
Mar 17, 2008, 04:13 PM
I have been looking through sample code and books about the iPhone SDK for about 5 days now. I have limited understanding about these things, even after multiple "blackbox" tests. Questions:

lets say I have:
NSString *input = self.textField.text;
...
How can I test the String's value to another string?

By this is mean why wont this
if(input == @"whatever) { ... }
work?

I also have questions about ViewControllers and CGRects: what are they? When do I use them?

Any help is appreciated because I am frustrated and tired of this.



admanimal
Mar 17, 2008, 04:38 PM
How much general programming experience do you have? It sounds like you might want to start with the basics before diving into SDK-specific issues.

To answer your question about the string comparison, you'll want to use [input isEqualToString:@"whatever"].

I'm not entirely familiar with Obj-C, but I'm guessing the reason that input == @"whatever" doesn't work is because input is actually a pointer, so you are comparing a pointer (i.e. a memory address) to the string @"whatever", which semantically doesn't make sense.

Duke Leto
Mar 17, 2008, 05:08 PM
As for programming experience, I have had about four years with Visual Basic, 2 years with ActionScript, about a year with Java, and some other languages.

Thank you for that function though, I have been looking for something like that :)

Soulstorm
Mar 17, 2008, 06:37 PM
As for programming experience, I have had about four years with Visual Basic, 2 years with ActionScript, about a year with Java, and some other languages.

Thank you for that function though, I have been looking for something like that :)

Oops. Sorry to disappoint, but you need to learn more. Java, VB or ActionScript will not teach you the most basic principle in Objective C (and almost any C-like language): The concept of pointers and references. That will be the key into understanding why your code doesn't work, and the concept behind memory management in Cocoa. You have a lot of ground to cover before you actually start programming anything, my friend.

Duke Leto
Mar 17, 2008, 07:21 PM
Oh well.

Maybe once I am older.

Whatever.

gifford
Mar 17, 2008, 07:22 PM
Oops. Sorry to disappoint, but you need to learn more. Java, VB or ActionScript will not teach you the most basic principle in Objective C (and almost any C-like language): The concept of pointers and references. That will be the key into understanding why your code doesn't work, and the concept behind memory management in Cocoa. You have a lot of ground to cover before you actually start programming anything, my friend.

I wouldnt say the person is doomed in the slightest, presuming you mean AS3 you have at least 2 oo programming languages under your belt (i dont really know much about VB except that its something PC people do).
And both have C like 'for', 'if', 'while's, and both use Objective C 2's '.' to drill down properties. And java uses garbage collection last i knew (not that the iPhone in its current form does).
I dont think he/she will have to much of a problem personally. There are many similarities.

Do a google for 'c structs', it's one of the few skills you may be missing, but you will understand them in 10 mins.

Also, the Cocoa framework can be extremely daunting at first, but will become familiar in time.

Duke Leto
Mar 17, 2008, 07:26 PM
I did forget to mention C++ .. and my experience with VB was only to learn about conditionals, variables, functions, and that basic stuff. Then, around .. 5-6th grade, I got a Mac and learned C++ .. . then later I got Flash, then I started messing around with Java, and here I am now.

gifford
Mar 17, 2008, 07:31 PM
I did forget to mention C++ .. and my experience with VB was only to learn about conditionals, variables, functions, and that basic stuff. Then, around .. 5-6th grade, I got a Mac and learned C++ .. . then later I got Flash, then I started messing around with Java, and here I am now.

Then indeed you shall have no problems.

cazlar
Mar 17, 2008, 07:32 PM
If you are set on learning Obj-C and Cocoa, I'd start by playing around by making a simple Mac program before you start on the iPhone. There's a lot more sample code and other resources out there that will help with this. If you come across something and you don't know why it isn't working, hit Apple's docs (in your example, a good read of NSString's docs would have helped find the solution).

Knowing about pointers and references is important, but you can still code with only a vague understanding of them (maybe not code _well_, but whatever).

gnasher729
Mar 17, 2008, 07:39 PM
If you want to know how to compare NSStrings: Go to developer.apple.com, type NSString in the search box, select "NSString Class Reference" and read it. If you want to know about CGRect: Go to developer.apple.com, type CGRect in the search box, I hope you get the picture.

Sijmen
Mar 17, 2008, 08:14 PM
Of course, there's also Help –> Documentation in Xcode. You can also Option-double click any word in your code to get a quick lookup. As if that's not enough, try Help –> Show Research Assistant if you can afford the screen real estate .

Duke Leto
Mar 17, 2008, 08:17 PM
Thanks to some of your help, I was able to create a small application that displays an image, and when you press 'next', it moves to the next image. It gets the names of the images from a file that it reads and turns into an array. I know that this is not a very big application, but it has deepened my understanding in many UIKit Elements, and yes, Strings.

admanimal
Mar 17, 2008, 08:36 PM
Oh well.

Maybe once I am older.

Whatever.

No way! Learn now! It sounds like you're on the right track.

lucasgladding
Mar 17, 2008, 09:35 PM
I would check out Cocoa Programming for Mac OS X from Aaron Hillegass. It is an excellent book and should get you started. There is a 3rd edition in the works that should cover some of the changes for Objective C 2.0.

http://bignerdranch.com/products/cocoa1.shtml
http://www.amazon.com/Cocoa-Programming-Mac-OS-3rd/dp/0321503619

You can also check out
http://cocoadevcentral.com/

The other advice is to spend some serious time getting to know delegates, notifications, key value observing, etc. The class references and guides will give you a good idea of what can be done without subclassing.

Soulstorm
Mar 18, 2008, 04:00 AM
Oh well.

Maybe once I am older.

Whatever.

I didn't mean to discourage you. And seems like you know C++, so you will have no problems. Check the other posters' responses, and do a revision on pointers.