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

Similar Threads
thread Thread Starter Forum Replies Last Post
Privacy settings blocking wp application vjaaan Mac Applications and Mac App Store 3 Mar 29, 2014 11:26 AM
Time Calculation as shift in iOS arungre iPhone/iPad Programming 6 Nov 29, 2013 03:13 PM
Automator: trigger a settings change in an application when Ethernet port connected? bigsexyy81 OS X 10.8 Mountain Lion 1 Oct 20, 2013 12:34 PM
"application active settings canceled log out" Rossatron OS X 10.8 Mountain Lion 0 May 8, 2013 09:29 AM
Application to record from a webcam with custom settings? Jethryn Freyman PowerPC Macs 1 Sep 24, 2012 10:04 AM

Forum Jump

All times are GMT -5. The time now is 01:18 PM.

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

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