Skip to content

Instantly share code, notes, and snippets.

View diegosanchezr's full-sized avatar

Diego Sánchez diegosanchezr

  • Facebook
  • London, United Kingdom
View GitHub Profile
@diegosanchezr
diegosanchezr / TypedNotifications.swift
Created May 16, 2016 20:21
Typed notifications with NSNotificationCenter
public protocol BPFNotification: AnyObject {
static var notificationName: String { get }
static var payloadKey: String { get }
}
public extension BPFNotification {
public static var notificationName: String {
return NSStringFromClass(Self)
}
struct Result: CustomStringConvertible {
let size: CGSize
let detail: String
var description: String {
return "\(size) \(detail)"
}
}
let texts: [String] = [
"Lorem ipsum dolor sit amet 😇, https://github.com/badoo/Chatto consectetur adipiscing elit , sed do eiusmod tempor incididunt 07400000000 📞 ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute ir incoming:incoming, #:7",
@diegosanchezr
diegosanchezr / protocol-extension-unexpected-implementation.swift
Created February 20, 2016 12:18
Protocol extensions unexpected implementation
protocol MyProtocol {
func doSomething()
}
extension MyProtocol {
func doSomething() {
print("default impl")
}
}
@diegosanchezr
diegosanchezr / Protocol-covariance.swift
Created February 17, 2016 12:54
Protocol covariance
// Covariance works properly with classes:
class MyType {}
class MySubtype: MyType {}
class MyClass {
func createMyType() -> MyType {
return MyType()
}
}
@diegosanchezr
diegosanchezr / crash-xcode7.3-b2.swift
Last active January 28, 2016 13:08
Crash Xcode 7.3 b2
import UIKit
public class BaseCellT<BubbleViewType where BubbleViewType:UIView>: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
self.bubbleView = self.createBubbleView()
}
@diegosanchezr
diegosanchezr / CollectionTypes.swift
Last active October 28, 2015 13:46
Protocol conformance in collections
import Foundation
protocol UniqueIdentificableProtocol {
var uid: String { get }
}
protocol UniqueIdentificableSubtypeProtocol: UniqueIdentificableProtocol {
var c: String { get }
}
@diegosanchezr
diegosanchezr / didSetLoop.swift
Created October 21, 2015 14:08
Infinite loop didSet
protocol AProtocol {
var someString: String { get }
}
class A: AProtocol {
var someString: String
init() {
someString = "A"
}
}
@diegosanchezr
diegosanchezr / Observer.swift
Last active October 3, 2015 13:14
Observers swift
import Foundation
public protocol Observable : class {
typealias ObserverType
func addObserver(observer : ObserverType)
func removeObserver(observer : ObserverType)
}
let observersAssociatedKey = "observersKey"
- (void)stringSizeBug {
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 2;
paragraphStyle.alignment = NSTextAlignmentCenter;
NSDictionary *attributes = @{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSParagraphStyleAttributeName : paragraphStyle,
NSFontAttributeName : [UIFont systemFontOfSize:12]
};