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 | |
//MARK: - UIButton Animations | |
extension UIButton { | |
// Contract and retract animation | |
func contractRetractBtn(duration: Double) { | |
let contraction = CASpringAnimation(keyPath: "transform.scale") | |
contraction.duration = duration | |
contraction.fromValue = 0.96 |
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
// MARK: - Associated Values | |
enum FavouriteAppleProducts { | |
case iphone(String) | |
case macbookPro(String) | |
case iPod(String) | |
} | |
let myFavouriteIpod = FavouriteAppleProducts.iphone("iPhone 14 pro") |
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
struct LegoCar { | |
static var defaultColour: UIColor = .red | |
static var defaultWheels = 4 | |
var colour: UIColor | |
var wheels: Int | |
static func create() -> Self { | |
return self.init(colour: defaultColour, wheels: defaultWheels) | |
} |
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
let data = Data("Hello, world!".utf8) | |
let string = String(data: data, encoding: .utf8) |
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
func convertIntToString(_ string: String) -> Int { | |
guard let intValue = Int(string) else { return 0 } | |
return intValue | |
} | |
convertIntToString("123") |
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
let car = "BMW,Tesla,Range,Porsche" | |
let cars = car.components(separatedBy: ",") //["BMW", "Tesla", "Range", "Porsche"] |
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
let str = "Apple" | |
let index = str.index(str.startIndex, offsetBy: 3) | |
let mySubstring = str.prefix(upTo: index) |
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
let messages = ["Hi", "welcome", "to", "my", "home"] | |
let combinedMessages = messages.joined(separator: " ") //Hi welcome to my home |
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
var bobScore = "Bob has a score of \(2 * 3)" |
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
let names = ["Bob", "Alice", "Mallory"] | |
for (index, name) in names.enumerated() { | |
print("Index \(index): \(name)") | |
} |
OlderNewer