Swift basics - Extensions
Extensions:
When you need to edit a type like string without overriding existing functionality:
extension String
{
var firstLetter: Characters?{ get return self.characters.first}}
func reverse() -> String{//... }
}
To call it:
var myString = "ABC"
print(myString.firstLetter)
When you need to edit a type like string without overriding existing functionality:
extension String
{
var firstLetter: Characters?{ get return self.characters.first}}
func reverse() -> String{//... }
}
To call it:
var myString = "ABC"
print(myString.firstLetter)
Comments
Post a Comment