Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Andyy Hope andyyhope

🎯
Focusing
View GitHub Profile
View TypecasingAndTypechecking.swift
struct Foo { }
enum Bar {
case hero(Any)
}
let foo = Foo()
let bar = Bar.hero(foo)
if case let .hero(foo) = bar, foo is Foo {
View Blog_UIViewAnimationSyntaxSugar.swift
//:
//: 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 {
View UserDefaultable.swift
//:
//: UserDefaultable.swift
//:
//: Created by Andyy Hope on 18/08/2016.
//: Twitter: @andyyhope
//: Medium: Andyy Hope, https://medium.com/@AndyyHope
import Foundation
// MARK: - Key Namespaceable
View Blog_Typecasing.swift
// Swift: Typecasing
// Enums as data models?
//
// Author: Andyy Hope
// Twitter: @andyyhope
// Medium: medium.com/@andyyhope
import Foundation
// MARK: - Models
View Blog_SyntaxCheatCodes.swift
// Swift: Syntax Cheat Codes
// ↑ ↑ ↓ ↓ ← → ← → B A
//
// Author: Andyy Hope
// Twitter: @andyyhope
// Medium: medium.com/@andyyhope
import UIKit
View Notifier.swift
import Foundation
// MARK: - Protocol
public protocol Notifier {
associatedtype Notification: RawRepresentable
}
public extension Notifier where Notification.RawValue == String {
View NotifierExtension_AddObserver.swift
static func addObserver(observer: AnyObject, selector: Selector, notification: Notification) {
let name = nameFor(notification)
NSNotificationCenter.defaultCenter()
.addObserver(observer, selector: selector, name: name, object: nil)
}
View NotifierExtension_RemoveObserver.swift
static func removeObserver(observer: AnyObject, notification: Notification, object: AnyObject? = nil) {
let name = nameFor(notification)
NSNotificationCenter.defaultCenter()
.removeObserver(observer, name: name, object: object)
}
View NotifierExtension_NotificationName.swift
private static func nameFor(notification: Notification) -> String {
return "\(self).\(notification.rawValue)"
}
View NotifierExtension_PostNotification.swift
static func postNotification(notification: Notification, object: AnyObject? = nil, userInfo: [String : AnyObject]? = nil) {
let name = nameFor(notification)
NSNotificationCenter.defaultCenter()
.postNotificationName(name, object: object, userInfo: userInfo)
}