Skip to content

Instantly share code, notes, and snippets.

@mehmetfarhan
Created September 25, 2020 21:42
Show Gist options
  • Save mehmetfarhan/eeeab02f8c984cd95e49108f5deef865 to your computer and use it in GitHub Desktop.
Save mehmetfarhan/eeeab02f8c984cd95e49108f5deef865 to your computer and use it in GitHub Desktop.
Destructuring
import UIKit
/*
Destructuring is the practice of pulling a tuple apart into multiple values in a single assignment.
*/
// MARK: - Destructuring
extension String {
var splittedName: (String, String) {
let parts = components(separatedBy: " ")
return (parts[0], parts[1])
}
}
// MARK: - Test
let (firstName, lastName) = "Mohammad Farhan".splittedName
print(firstName) // Mohamamd
print(lastName) // Farhan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment