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
function freespace() { | |
# rm -rf ~/Library/Containers/com.apple.mail/Data/Library/Mail\ Downloads/ | |
# https://stackoverflow.com/a/53199763/3724306 | |
echo "1. Boot all the sims that I want to use" | |
echo "2. remove all the simulators that I don't have booted" | |
echo "Run: xcrun simctl list | grep -w \"Shutdown\" | grep -o \"([-A-Z0-9]*)\" | sed \'s/[\(\)]//g\\' | xargs -I uuid xcrun simctl delete uuid" | |
echo "Cleaning ~/Library/Caches/com.apple.dt.Xcode..." | |
rm -rf ~/Library/Caches/com.apple.dt.Xcode/* |
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 Foundation | |
import ObjectiveC | |
// MARK: - DynamicTypeResponsive | |
protocol DynamicTypeResponsive { | |
var respondsToDynamicTypeChanges: Bool { get set } | |
} | |
extension UILabel: DynamicTypeResponsive { | |
var respondsToDynamicTypeChanges: Bool { |
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
// TO BE CONTINUED... | |
extension Notification.Name { | |
func post(to notificationCenter: NotificationCenter = .default, withObject object: Any? = nil) { | |
notificationCenter.post(name: self, object: object) | |
} | |
} | |
extension Notification { | |
struct MyApp { |
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 Foundation | |
extension Data { | |
var hexString: String { | |
let hexString = map { String(format: "%02.2hhx", $0) }.joined() | |
return hexString | |
} | |
} |
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 photo = try! loadImage("./Resources/John Appleseed.jpg") |
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 x = try! divide(2, 2) |
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
// Using optional try | |
let x = try? divide(0, 2) // (Yes you can use an if let/guard/whatever to unwrap it safely) | |
// Using do-catch | |
let y: Float? | |
do { | |
y = try divide(0, 2) | |
} catch { // exhaustive just for testing | |
y = nil | |
} |
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 calculate() { | |
do { | |
let x = 2 | |
let y = 2 | |
let result = try divide(x, y) | |
resultLabel.text = String(result) | |
} catch DivisionErrorEnum.DividendIsZero(let code) { | |
print("Your message when the DIVIDEND is zero. \nDetails: Execution failed with code \(code).") | |
} catch DivisionErrorEnum.DivisorIsZero(let code) { | |
print("Your custom message when the DIVISOR is zero. \nDetails: Execution failed with code \(code).") |
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
enum DivisionErrorEnum: ErrorType { | |
case DividendIsZero(code: Int) | |
case DivisorIsZero(code: Int) | |
} |
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 calculate() { | |
do { | |
let x:Float = 2.0 | |
let y:Float = 2.0 | |
let result = try divide(x, y) | |
resultLabel.text = String(result) | |
} catch DivisionErrorEnum.DividendIsZero(let msg) { | |
print(msg) | |
} catch DivisionErrorEnum.DivisorIsZero(let msg) { | |
print(msg) |
NewerOlder