Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

return multiple values from a function swift

func returnMultipleValues() -> (String, Int, Double) {
    return ("Swift Tuple", 12, 3.14)
}

//Calling Function
let result = returnMultipleValues()

let nameString = result.0
let intValue = result.1
let doubleValue = result.2
Comment

Swift Function with Return Multiple Values

func checkMarks() -> (String, Int) {
  ...
  return (message, marks)
}
Comment

Swift Multiple Return Values

func compute(number: Int) -> (Int, Int, Int) {

  var square = number * number

  var cube = square * number
  
  return (number, square, cube)
}

var result = compute(number: 5)

print("Number:", result.0)
print("Square:", result.1)
print("Cube:", result.2)
Comment

PREVIOUS NEXT
Code Example
Swift :: how to add button dynamically in swift 4 
Swift :: Save structure in userdefaults ios swift 
Swift :: swift filter dictionary 
Swift :: swiftui play mp3 
Swift :: how to download swift 
Swift :: swift how to change the header color 
Swift :: swift create array from range 
Swift :: using swipe gesture recognizer swift 
Swift :: swift post request 
Swift :: swift collectionview scrolltoitem 
Swift :: and in swift4 
Swift :: tuple swift 
Swift :: swift print 
Swift :: Module compiled with Swift 5.3 cannot be imported by the Swift 5.3.1 compiler 
Swift :: swift contains 
Swift :: enviroment dissmiss swiftui 
Swift :: swift 5 make image fit uiimageview 
Swift :: add months to date swift 
Swift :: hello world in swift 
Swift :: how to clear text file swift 
Swift :: === in swift 
Swift :: latex tall parentheses 
Swift :: Swift Handling Errors Using do-catch Statement 
Swift :: Swift Named Associated Values 
Swift :: ring Desktop, WebAssembly and Mobile Using QTableWidget 
Swift :: swift increase int value 
Swift :: separator style swiftui list 
Swift :: Swift self property 
Swift :: swift how to dereference unsafemutablepointer 
Swift :: protocol oriented programming 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =