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

Duke Leto

macrumors regular
Original poster
Mar 17, 2008
166
0
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

macrumors 68040
Apr 22, 2005
3,531
2
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:mad:"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

macrumors regular
Original poster
Mar 17, 2008
166
0
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

macrumors 68000
Feb 1, 2005
1,887
1
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.
 

gifford

macrumors 6502
Jun 11, 2007
422
0
Miserable England
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

macrumors regular
Original poster
Mar 17, 2008
166
0
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

macrumors 6502
Jun 11, 2007
422
0
Miserable England
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

macrumors 6502
Oct 2, 2003
492
11
Sydney, Australia
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

Suspended
Nov 25, 2005
17,980
5,565
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

macrumors 6502a
Sep 7, 2005
709
1
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

macrumors regular
Original poster
Mar 17, 2008
166
0
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.
 

lucasgladding

macrumors 6502
Feb 16, 2007
319
1
Waterloo, Ontario
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.