O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 25The Many Faces of Swift Functions

by Natasha Murashev

The standard against which Swift is evaluated is Objective-C, which Apple intends to replace with Swift for its developers. Although Objective-C has some strange-looking syntax compared to other programming languages, the method syntax is pretty straightforward once you get the hang of it. Here’s a quick throwback:

 + (void)mySimpleMethod
 {
  // class method
  // no parameters
  // no return values
 }
 
 - (NSString *)myMethodNameWithParameter1:(NSString *)param1
  parameter2:(NSNumber *)param2
 {
  // instance method
  // one parameter of type NSString pointer,
  // one parameter of type NSNumber pointer
  // must return a value of type NSString pointer
  return @"hello, world!"; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required