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

My Code Is Wacked

Discussion in 'iPhone/iPad Programming' started by mack255, Apr 3, 2009.

  1. macrumors member


    Whats wrong with my code i said to change the button title to orange when it says what color is the sun but instead it changes when it says wrong please help

    Attached Files:

  2. Guest


    = doesn't compare things. It assigns values. Use == to compare. But you can't in this case as you'd be comparing an object's address against a literal string. You need to use the isEqualToString: method.
  3. macrumors member


    how do i use that method
  4. macrumors member


    a better question is how would i write the code
  5. Moderator


    Staff Member

    The same way you call any Objective-C method. With a
    [receiver message]
    where "receiver" is the class or instance and "message" is the method, with arguments, if necessary.
  6. macrumors 6502a

    Actually, the Sun is white!

    b e n
  7. macrumors member


    im new can you please tell me the full code im brand new started a couple days ago
  8. Moderator


    Staff Member

    This is pretty basic Objective-C programming concepts. I'd suggest you step back and learn the basics before you continue with any real coding.
  9. macrumors member


    please just tell me i don't understand i couldn't find any good websites to teach me and im broke and can't buy any books
  10. macrumors 6502a

    Well, if you're learning you probably want to understand the concepts rather than assign someone to write code for you. The Apple developer docs are more than sufficient if you don't want to buy a book right now.

    So do you understand the concept that objects belong to a class and can respond to messages (also called instance methods)? If so, then the strings you have belong to the class NSString, and so you can find various instance methods in the docs for NSString. There is a method there that allows you to compare one instance of NSString to another.

    Your overall approach to managing questions and answers like this will get pretty painful quickly. But it's a good learning exercise, and then you can learn ways to make this easier and more efficient.

    But I would point out that string comparison is not your main problem. The issue is the logic itself. The method that is fired by the top button won't be executed until after the user hits that button.

    So that's really the reason why you don't get the button "Orange" until after the user has pressed that top button.

    Does that make sense?
  11. Moderator


    Staff Member

    Have you checked out the guides and stickies at the top of the iPhone Programming forum?
  12. macrumors 6502

    If someone "just tells you" you won't learn anything. You couldn't find any good websites??? Did you even look? Here, I have a link that will help you:

  13. macrumors member


    actually i learn really well if someone tells me the code
  14. Moderator


    Staff Member

    Of course! No learning required then. You've already got the answer! :D
  15. macrumors 6502a

    Read my post again, I told you exactly which class to look in.

    I think the point you may be missing is that coding with Cocoa or any similar framework is a process of looking through the framework documentation for something you need, and then using it in your code. This is true even after you've done this for decades.

    So if you don't have the time or focus or energy or whatever to crack open the documentation, then you've just picked a bad hobby for yourself. Not trying to be mean, it's just how programming works. If you don't want to do it, then save yourself a lot of trouble and just don't do it. It's that easy.

    But if you do decide to put the effort in, then we can talk about the logic problems (which I wrote about already in my earlier post.)

    Good luck whatever you decide to do. I would recommend the hello world primer on the Apple developer site. Or any of the other video and web primers that people talk about on this forum. Just to get the basics down first.

    BTW, your code already has multiple examples of sending messages to objects. This is exactly what you need to do with your NSStrings. So if you wrote your code, then you know what to do. If you just copied that code from someone else, then I think you've proven that you don't really learn from copying code.
  16. macrumors 6502

    I'm an awesome physicist when someone writes all the proofs for me.

Share This Page