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 Jan 21, 2009, 12:34 AM   #1
vidyareef
macrumors newbie
 
Join Date: Jan 2009
function takes string parameter and returns string value

Hello!

can anyone give me an example of how to write function in xcode that takes on string parameter and after concatenation returns another string value.

I did a function,
-(void)Change{
.
.
.
}

but this does not return any value and also doesn't pass parameter.

I tried
-(NSString *) ChangeCase(NSString* String1){

}

but it doesn't work and i am getting errors.
vidyareef is offline   0 Reply With Quote
Old Jan 21, 2009, 03:52 AM   #2
jnic
macrumors 6502a
 
Join Date: Oct 2008
Location: Cambridge
http://cocoadevcentral.com/d/learn_objectivec/
jnic is offline   0 Reply With Quote
Old Jan 21, 2009, 06:33 AM   #3
CommanderData
macrumors regular
 
Join Date: Dec 2007
Quote:
Originally Posted by jnic View Post
Seconded. But seriously this is really basic Objective-C stuff, not even related to the iPhone SDK. If you don't get a grasp of the basics, you'll never be able to handle the harder stuff yet to come.
CommanderData is offline   0 Reply With Quote
Old Jan 21, 2009, 04:50 PM   #4
xsmasher
macrumors regular
 
Join Date: Jul 2008
Quote:
Originally Posted by vidyareef View Post
but it doesn't work and i am getting errors.
You were very close. I added a colon, and moved a parenthesis.
In objective C, the parameters don't go in parentheses.

Code:
-(NSString *) ChangeCase:(NSString*) String1{
     upperString = [string1 capitalizedString];
     return upperString;
}
Call it with
NSString* newString = [self ChangeCase: @"Hey."];

Code like this would return an uppercased string. That string is likely set to autorelease though, so retain it if you need to keep it around.

Note that the usual style is to have variables and methods start with a lowercase letter. So ChangeCase should be changeCase, and String1 should be string1. This will not change the operation, but it makes the code easier to understand.
xsmasher 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
Format string is not a string literal. larswik Mac Programming 5 Jan 17, 2014 10:45 PM
Search a string for a String of a specific format. ncaissie iPhone/iPad Programming 19 Nov 15, 2013 10:42 AM
Resolved: hpple and string encoding Warren93 iPhone/iPad Programming 2 Aug 16, 2013 01:10 PM
string shortcuts duden32 OS X 10.8 Mountain Lion 3 May 16, 2013 02:34 AM
String Encoding manga iPhone 1 Jan 8, 2013 12:04 AM

Forum Jump

All times are GMT -5. The time now is 04:10 AM.

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

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