Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Last end of my wits! Help! (XCODE OSX, basic app nightmare)

Hi Folks,


I literally spent an entire night trying to solve this...scoured the net/read tons of cryptic

articles. I really am on my last braincell here and would appreciate if someone can help me.


I am trying to create a simple app in OSX where I click on a thumbnail size picture

and a random bit of text will appear.


The Interface is a simple window with a simple picture, text label. I associated everything

via the delegate...yet the code keeps giving me this error message. I read that the 'string'

needs to be modified (and this is where I start losing my hair)


Below is the code I wrote:


The Header:


#import <Cocoa/Cocoa.h>


@interface AppAppDelegate : NSObject <NSApplicationDelegate> {

@private

NSTextField *textoutput;

}


- (IBAction)button2:(id)sender;

@property (assign) IBOutletNSTextField *textoutput;


@end


And the Implement:


#import "AppAppDelegate.h"


@implementation AppAppDelegate;

@synthesize textoutput;



- (void)applicationDidFinishLaunching:(NSNotification *)aNotification

{

int randomnumber = arc4random() % 3+1;

- (IBAction)button2:(id)sender {

switch ([sender randomnumber]) {

case 1:

textoutput.text = @"Test1";

break;

case 2:

textoutput.text = @"Test2";

break;

case 3:

textoutput.text = @"Test3";

break;

case 4:

textoutput.text = @"Test4";

break;

default break;

}

}


}


@end


Highlighted in red: I keep getting a "Expected Expression" error or some other cryptic error message.


I would greatly appreciate any help/advice/corrections! Someone helped me before with a simple 'dice' game

and that help helped me beyond all comprehension in basic coding...I now want to figure out the User Interface!!!


Thanks

Posted on Apr 13, 2012 8:49 AM

Reply
17 replies

Apr 13, 2012 10:47 AM in response to etresoft

etresoft wrote:


You can't define one function inside another.


Can you please explain to me in laymen's terms what this means? I gather the following below is too 'nested'? How do you correct it?


Thank you.


#import "SpenceAppAppDelegate.h"


@implementation SpenceAppAppDelegate;

@synthesize textoutput;



- (void)applicationDidFinishLaunching:(NSNotification *)aNotification

{

int randomnumber = arc4random() % 3+1;

- (IBAction)button2:(id)sender {

switch ([sender randomnumber]) {

case 1:

textoutput.text = @"Test1";

break;

case 2:

textoutput.text = @"Test2";

break;

case 3:

textoutput.text = @"Test3";

break;

case 4:

textoutput.text = @"Test4";

break;

default break;

}

}


}


@end

Apr 13, 2012 11:27 AM in response to claimsfour

#import "SpenceAppAppDelegate.h"


@implementation SpenceAppAppDelegate;

@synthesize textoutput;


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification

{

int randomnumber = arc4random() % 3+1;

}


- (IBAction)button2:(id)sender

{

switch ([sender randomnumber])

{

case 1:

textoutput.text = @"Test1";

break;

case 2:

textoutput.text = @"Test2";

break;

case 3:

textoutput.text = @"Test3";

break;

case 4:

textoutput.text = @"Test4";

break;

default break;

}

}


@end

Apr 13, 2012 2:11 PM in response to etresoft

etresoft wrote:


If I type if for you, you aren't going to learn anything. Plus I charge $200 an hour 🙂


You need a colon after default.

You can only switch on an integer.

There is no text property in an NSTextField.


After that, you have to accept the learning to program is a trial and error process. By "error" I mean 63 times in a row.


I'm not asking you/anyone to write my apps for me.

Also, if anyone wants to 'steal' my code and make "millions" off of it, be my guest.


I came here after I hit 'error' 64 times in a row.

(A solid eight hours of nonstop trial/error/tutorials/forum reads and zip/nada).


There is no text property in an NSTextField.


This does not make sense (to me). However I will interpret it as 'try something different'


Thanks for your insight on the colon/integer.

Apr 13, 2012 2:33 PM in response to claimsfour

claimsfour wrote:


I'm not asking you/anyone to write my apps for me.

Also, if anyone wants to 'steal' my code and make "millions" off of it, be my guest.


That was a joke, hence the smiley face.


I came here after I hit 'error' 64 times in a row.

(A solid eight hours of nonstop trial/error/tutorials/forum reads and zip/nada).


There is no text property in an NSTextField.


This does not make sense (to me). However I will interpret it as 'try something different'


There is a another option in addition to trial and error - research. You might want to look at sample code too.



Apr 13, 2012 2:40 PM in response to etresoft

etresoft wrote:



claimsfour wrote:




I'm not asking you/anyone to write my apps for me.

Also, if anyone wants to 'steal' my code and make "millions" off of it, be my guest.




That was a joke, hence the smiley face.




I came here after I hit 'error' 64 times in a row.

(A solid eight hours of nonstop trial/error/tutorials/forum reads and zip/nada).


There is no text property in an NSTextField.


This does not make sense (to me). However I will interpret it as 'try something different'




There is a another option in addition to trial and error - research. You might want to look at sample code too.





Research, books, online tutorials (Spent weeks researching before I developed the nerve to try coding)


...I once read somewhere NASA in the 50's considered

bringing in a witch doctor to deal with their "Vanguard" program

(Only 3 successful launches out of 11).


The only thing more difficult than trying to comprehend Objective-C...are women! 😁

Apr 14, 2012 7:12 AM in response to claimsfour

SOLUTION!!!!


These two youtube tutorials: PERFECTLY explains how to make an app. A

few things (like NSObject) I didn't realize fully. These two tutorials will pretty

much get anyone on their way to making apps.


Part 1: http://www.youtube.com/watch?v=GLxTuluYdZg


Part 2: http://www.youtube.com/watch?v=CgrDSW0dHy4


I FINALLY got my little app made, and it was easily one of the more

satisfying feelings in ages.


Y'know...I might after all have a future in programming. There is light

at the end of the tunnel!!!! NEVER GIVE UP!

Apr 14, 2012 8:00 AM in response to etresoft

It's never easy!


I finished the app, did a 'build' and it worked perfectly on my 10.7 macbookpro.


But when I sent it to my MacPro running 10.6: IT CRASHED


I then repeatedly tried in XCODE to recompile the app to work at 32bit/10.6


I am now getting this error message:


Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/ usr/bin/clang failed with exit code 1



help?

Apr 14, 2012 10:12 AM in response to claimsfour

claimsfour wrote:


I finished the app, did a 'build' and it worked perfectly on my 10.7 macbookpro.


But when I sent it to my MacPro running 10.6: IT CRASHED

You've got to walk before you can run. If you must run on the 10.6 machine, you have to make sure to targen only that operating system. It will still run on Lion. If you target Lion only, it won't run on 10.6.

Apr 14, 2012 9:21 PM in response to etresoft

etresoft wrote:


claimsfour wrote:


I finished the app, did a 'build' and it worked perfectly on my 10.7 macbookpro.


But when I sent it to my MacPro running 10.6: IT CRASHED

You've got to walk before you can run. If you must run on the 10.6 machine, you have to make sure to targen only that operating system. It will still run on Lion. If you target Lion only, it won't run on 10.6.


More like crawl on my stomach naked over broken glass!


I *finally* got a basic app running, and was able to figure out the NSString function/basic math.


So now I can make a 'basic' calculator. (which is better than a "Hello World") app.


I tried the 'targeting' on my 10.7 Macbookpro to have the app output to 10.6, but I kept getting this "CLANG" error. What in HADES is that?!?!?!?


So...I rewrote the app again on my 10.6 Mac Pro, and this time it worked.


There's obviously something I'm not doing right on my 10.7. XCODE can't be that messed up on outputting a basic 10.6 app.


Seems like each time I hit a small 'victory' there's about a dozen more defeats.


I found drinking hard liquor helps, because you kind of lose focus...and suddenly the "ALERT/ERRORS" in Xcode will dissapear and I'll gaze at the code and go "So that's how I fixed it."


That's XCODE in a nutshell, drink hard liquor and keep bashing at

the keyboard until the 'red/yellow' errors dissapear.


Lamb's Navy Rum is great, has a wonderully thick syrup taste to it, and mixed with Coca cola...perfecto!

Avoid doing 'shots' because the XCODE screen will begin to look hazy and your hands will begin stumbling

over the keyboard. Just keep the alcohol flowing into you at a steady/even rate.

Apr 15, 2012 1:38 AM in response to etresoft

XCODE 4.0.2 (On my Mac Pro 10.6.8) Deployment target: No problem building my app for 10.6, 10.5 (I had a friend

who still uses 10.5 run it no problem).


XCODE 4.3.2 (On my MBP 10.7) When I try doing the exact same thing (adjust Deployment target): I get a littany

of errors/fails.


Question: How is it that I'm doing the exact same thing, and on 4.0.2. it works without a hitch, whereas

4.3.2. I'm getting a ton of errors?


Please don't tell me this is an Apple 'feature'!

Last end of my wits! Help! (XCODE OSX, basic app nightmare)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.