1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

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

Discussion in 'Mac Programming' started by Duke Leto, Mar 17, 2008.

  1. macrumors regular

    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) { ... }

    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.
  2. macrumors 68040

    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.
  3. macrumors regular

    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 :)
  4. macrumors 68000


    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.
  5. macrumors regular

    Oh well.

    Maybe once I am older.

  6. macrumors 6502


    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.
  7. macrumors regular

    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.
  8. macrumors 6502


    Then indeed you shall have no problems.
  9. macrumors 6502

    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).
  10. macrumors G5


    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.
  11. macrumors 6502a

    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 .
  12. macrumors regular

    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.
  13. macrumors 68040

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

    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.


    You can also check out

    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.
  15. macrumors 68000


    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.

Share This Page