by
8,516 29
1
5
3,056
0
Top 1% !
Famous
Easy-to-find
Specified
Pattern
Popularity: 4563rd place
Architectureia64
Extension4.0
Languageswift
LicenseMIT_X11

Swift Collections: Simple function with parameter

I want to pass a name (String) to a function and then print it out to the console.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/121749/Swift-Collections--Simple-function-with-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
=> Objective-C: -(void)outputName:(NSString *)nameString { NSLog(@"My name is %@",nameString); } To call this method within the same class: [self outputName:@"Mark"]; //Results in the outputName function being called and "My name is Mark" printed to the console. => Swift: In Swift, we define the input value first (in our case, the string value), followed by the Type (String). func outputName(nameString:String){ println("My name is: \(nameString)") } To call this method within the same class: outputName(@"Mark") //Results in the outputName function being called and "My name is Mark" printed to the console.

Other Steps and Solutions

If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus