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!"; ...

Get Functional Programming: A PragPub Anthology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.