This file contains hidden or 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
protocol PLAnimatableBorder { | |
func animateBorderWidth(toValue: CGFloat, duration: Double) | |
} | |
extension PLAnimatableBorder where Self: UIView { | |
/// animate the border width | |
func animateBorderWidth(toValue: CGFloat, duration: Double) { | |
let animation: CABasicAnimation = CABasicAnimation(keyPath: "borderWidth") | |
animation.fromValue = layer.borderWidth | |
animation.toValue = toValue |
This file contains hidden or 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
debug release release | |
function -Onone -O -Ounchecked | |
assert() YES NO NO | |
assertionFailure() YES NO NO** | |
precondition() YES YES NO | |
preconditionFailure() YES YES YES** | |
fatalError()* YES YES YES | |
– assert: checking your own code for internal errors | |
– precondition: for checking that your clients have given you valid arguments. |
This file contains hidden or 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
private let gradientLayer = CAGradientLayer() | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
super.layoutIfNeeded() | |
if let viewBounds = self.gradientView?.bounds { | |
self.gradientLayer.frame = viewBounds | |
} | |
} |
This file contains hidden or 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
xcrun simctl openurl booted "PROTOCOL://URLPATH/" |
This file contains hidden or 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
// Inside the app (SQLite) | |
lazy var persistentContainer: NSPersistentContainer = { | |
let container = NSPersistentContainer(name: "CoreDataUnitTesting") | |
container.loadPersistentStores { (description, error) in | |
if let error = error { | |
fatalError("Unresolved error \(error), \(error.userInfo)") | |
} | |
} | |
return container |
This file contains hidden or 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 performNetworkRequest(url: String, | |
completion: @escaping (Data?, Error?) -> Void) { | |
// create a url | |
let requestUrl = URL(string: url) | |
// create a data task | |
let task = URLSession.shared.dataTask(with: requestUrl!) { (data, response, error) in | |
completion(data, error) | |
} | |
task.resume() |
This file contains hidden or 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 baseUrl = "https://jsonplaceholder.typicode.com/" | |
let endpoints = ["posts", "comments", "albums", "photos", "todos", "users"] |
This file contains hidden or 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 group = DispatchGroup() | |
endpoints.forEach { endpoint in | |
group.enter() | |
performNetworkRequest(url: baseUrl + endpoint) { data, error in | |
print("Task \(endpoint) is done") | |
group.leave() | |
} | |
} | |
// notify the main thread when all task are completed |