Skip to content

Instantly share code, notes, and snippets.

View andyyhope's full-sized avatar

Andyy Hope andyyhope

View GitHub Profile
// Swift: Typecasing
// Enums as data models?
//
// Author: Andyy Hope
// Twitter: @andyyhope
// Medium: medium.com/@andyyhope
import Foundation
// MARK: - Models
@andyyhope
andyyhope / SwiftEvolution_EnumCaseCountFunctionality_AndyyHope.md
Last active March 12, 2020 13:05
Swift Evolution - Enum Case Count Functionality

Swift Evolution Proposal

Author: Andyy Hope

Enum Values() Functionality (Update)

It has been brought to my attention that there was more use for the unintended values() functionality that I had outline in my "Other Languages" Java example below.

On the Swift Evolution mailing list, one developer outlined their requirement to loop through an array of enum case values to add different states to objects.

Another example where a values array would be useful if the developer wants to do something different for each different case, such as setting an image on a UIButton subclass for each different UIControlState

// Swift: Syntax Cheat Codes
// ↑ ↑ ↓ ↓ ← → ← → B A
//
// Author: Andyy Hope
// Twitter: @andyyhope
// Medium: medium.com/@andyyhope
import UIKit
//:
//: UserDefaultable.swift
//:
//: Created by Andyy Hope on 18/08/2016.
//: Twitter: @andyyhope
//: Medium: Andyy Hope, https://medium.com/@AndyyHope
import Foundation
// MARK: - Key Namespaceable
import Foundation
// MARK: - Protocol
public protocol Notifier {
associatedtype Notification: RawRepresentable
}
public extension Notifier where Notification.RawValue == String {
//:
//: UIView Animation Syntax Sugar
//:
//: Created by Andyy Hope on 18/08/2016.
//: Twitter: @andyyhope
//: Medium: Andyy Hope, https://medium.com/@AndyyHope
import UIKit
extension UIView {