Created
September 25, 2020 21:42
-
-
Save mehmetfarhan/eeeab02f8c984cd95e49108f5deef865 to your computer and use it in GitHub Desktop.
Destructuring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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