Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 12, 2011, 03:57 AM   #1
boyplunder
macrumors regular
 
Join Date: Sep 2008
Location: UK
Calculation syntax problem using application settings

Hi all,

I have set up application settings for a project and created the same settings as a view in the app. All this works a treat. I am now trying to add a calculation that reads one of the settings and displays an image based on whether the setting is on or off.

Currently, my code is this:

Code:
//Check the map to use
	NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
	BOOL enabled = [defaults boolForKey:@"maptype"];
					
		if (enabled) {
			return (UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map2.jpg"]]);
		} else {
			return (UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map1.jpg"]]);
		}
self.imageView = tempImageView;
I get an error for each of the 'return' lines: Expected ")" before 'tempImageView'. The last line also says it's not declared, but this probably relates to the first issue.

I have been through it many times and am probably not seeing the wood for the trees, as they say. Could anyone give me a hand in understanding what the issue is?
boyplunder is offline   0 Reply With Quote
Old Jul 12, 2011, 04:32 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
You cannot declare a new variable within a return call like that. It serves no purpose. Return will exit the current method so all local variables will go out of scope. In addition your like setting self.imageView can never be reached due to the return statements.
robbieduncan is offline   0 Reply With Quote
Old Jul 12, 2011, 08:50 AM   #3
boyplunder
Thread Starter
macrumors regular
 
Join Date: Sep 2008
Location: UK
Appreciated.
It's pretty obvious what I am trying to do, I think, I just have to understand the right method of doing it for myself. From what you say I have to deal with the variables outside of the calculation, which is why the self.ImageView would never work, as there will never be a value to play with. Or not use a variable for this...

Aahh, the joy of learning!
boyplunder is offline   0 Reply With Quote
Old Jul 12, 2011, 08:53 AM   #4
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by boyplunder View Post
From what you say I have to deal with the variables outside of the calculation, which is why the self.ImageView would never work,
No, the self.imageView statement will never even get executed. This is very different from it not working. return exits the method right there and then. Any statements after it simply do not get executed. return does not flag a variable as the value you will return or anything like that.

I would suggest you need to learn very basic C as this is a pretty fundamental, core error.
robbieduncan is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Apple Script "spaces' syntax mishamazor Mac Programming 2 Oct 31, 2011 11:27 PM
Dot Syntax Problem Blakeasd Mac Programming 13 Feb 18, 2011 12:02 PM
Problems with application windows twistisme MacBook Pro 3 Feb 5, 2011 12:14 AM
Quick syntax problem mattpryor iPhone/iPad Programming 4 Mar 4, 2010 02:15 PM
Problems using Compressor application davideo78 Mac Applications and Mac App Store 0 Jun 23, 2006 02:21 PM


All times are GMT -5. The time now is 10:24 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC