0

I'm trying to create a Cocoa Objective-C program on my Snow Leopard MacBook running Xcode 4.2. Here/s what I want to do.

I have a textbox, a wrapping label, and a button. When you enter your name in the text box the wrapping label displays, "Have a merry merry christmas 'the name entered in the textbox'"

    //  AppDelegate.h
    #import <Cocoa/Cocoa.h>
    @interface AppDelegate : NSObject <NSApplicationDelegate>
    {
        IBOutlet id inputTextField;
        IBOutlet id outputTextField;
    }
    @property (assign) IBOutlet NSWindow *window;
    - (IBAction)pressMeButton:(id)sender;
    @end

    //  AppDelegate.m
    #import "AppDelegate.h"
    @implementation AppDelegate
    //Use the pressMeButton IBAction to tell the inputTextField to display on the outputLabelField
    - (IBAction)pressMeButton:(id)sender;
    { 
        char inputString = [inputTextField charValue];
        char outputString = [outputTextField charValue:(@"Have a merry merry Christmas, %@", inputString)];
        [outputTextField outputString];
    }
    @end

I tried NSString, but I'm not sure what I'm doing wrong here.

Machavity
  • 30,841
  • 27
  • 92
  • 100
rowrz
  • 31
  • 8
  • 1
    It's not _that_ urgent, Christmas is a couple of weeks off ;) – jrturton Dec 11 '11 at 18:37
  • Questions that describe themselves as "urgent" usually get downvoted... – Oliver Charlesworth Dec 11 '11 at 18:38
  • 3
    You should also actually include a question in your question. Which part are you having trouble with? – jrturton Dec 11 '11 at 18:42
  • 4
    People here aren't very patient, if you get criticized don't take it personally. – DarkDust Dec 11 '11 at 18:46
  • Any criticism should be taken as advice as to how to ask a better question (and get a better answer) - and look! It worked! Hope your mother enjoys it. – jrturton Dec 11 '11 at 18:47
  • 2
    A few points here: 1.) By posting here, you're agreeing to license your code under the Creative Commons. Your copyright notice is forfeit, and offers no value to your questions at any rate. 2.) You'll get faster and better answers if you find out the root of your problem and ignore the backstory. Try to describe what you're trying to do, what you've tried, and what is failing instead of telling a story. Look at some other questions around here to figure out what's expected of a question and answer. – Stefan Kendall Dec 11 '11 at 18:47
  • @2040techman: "Please don't criticize me." jrturton was being curteous. He could have voted to close this for too localized or "unsure what's being asked here." Instead, he tried to help you. – Stefan Kendall Dec 11 '11 at 18:50
  • Thanks everyone who helped this is my really my truly first Cocoa Objective-C app – rowrz Dec 11 '11 at 19:06

2 Answers2

4

You're close, but far at the same time. It doesn't make any sense to store a sequence of characters in a char type, which is for single char. Also, it doesn't make sense to call a message which is actually a local variable. Anyway, here's some code to help you.

- (IBAction)pressMeButton:(id)sender;
{
    [outputTextField setStringValue:
      [NSString stringWithFormat:@"Have a merry merry Christmas, %@",
                                   [inputTextField stringValue]]];
}

Be sure to read the introductory docs, and the StackOverflow faq to get an idea of how to ask questions in the expected format.

Community
  • 1
  • 1
sidyll
  • 57,726
  • 14
  • 108
  • 151
  • 1
    You're welcome. If this answer really solved your problem, please "accept" it by clicking in the checkmark below the vote count (left side of the answer). To know more about this Q&A system check the faq link I posted in the answer :-) – sidyll Dec 11 '11 at 18:47
  • You can also do `inputTextField.text` to access that string. That's my preferred method (pun intended). – gurooj Dec 11 '11 at 20:20
1

Or you could write it in AppleScript:

set nameReturned to the text returned of (display dialog "Name:" buttons {"OK"} default button 1 default answer "" with icon 2)
display dialog "Happy Christmas " & nameReturned & "!"
Espresso
  • 4,722
  • 1
  • 24
  • 33