Skip to content

Instantly share code, notes, and snippets.

View damianesteban's full-sized avatar
🦆
Playing with the ducks…

Damian Esteban damianesteban

🦆
Playing with the ducks…
View GitHub Profile
@kristopherjohnson
kristopherjohnson / List.swift
Last active August 21, 2016 02:04
Functional list type for Swift
import Foundation
/// Abstract functional list type
///
/// Concrete types are EmptyList<T> and Cons<T>
public class List<T>: SequenceType {
/// Return true if this is an empty list, false if not
public var isEmpty: Bool { return true }
@andymatuschak
andymatuschak / CollectionViewDataSource.swift
Last active February 12, 2021 09:44
Type-safe value-oriented collection view data source
//
// CollectionViewDataSource.swift
// Khan Academy
//
// Created by Andy Matuschak on 10/14/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
@mattdenner
mattdenner / gist:643f17ad52c374510a8c
Last active July 21, 2022 13:20
Segues using enums in Swift
extension UIViewController {
func performSegue<T:RawRepresentable where T.RawValue==String>(identifier: T, sender: AnyObject?)
self.performSegueWithIdentifier(identifier.rawValue, sender: sender)
}
}
@JaviLorbada
JaviLorbada / FRP iOS Learning resources.md
Last active April 20, 2025 21:15
The best FRP iOS resources.

Videos

------------
Conformances
------------
protocol AbsoluteValuable
Conformances:
Comparable
IntegerLiteralConvertible
SignedNumberType
func passAnyObject(param: AnyObject) {
print(param)
}
class MyClass {}
struct MyStruct {}
let a: Int = 1
let b = 2.0
//
// Signal+Extensions.swift
// Khan Academy
//
// Created by Nacho Soto on 10/1/15.
// Copyright © 2015 Khan Academy. All rights reserved.
//
import ReactiveCocoa
@gonzalezreal
gonzalezreal / ios-cell-registration-swift.md
Last active March 5, 2025 02:07
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@nickoneill
nickoneill / TableState.swift
Last active March 30, 2023 22:03
Easily add async state tracking to your UITableView data sources
protocol TableValuable {
associatedtype TableItem
static func loadingValue() -> TableItem
static func failedValue() -> TableItem
func value() -> TableItem
}
enum TableState<T: TableValuable> {
case Loading
case Failed
makeBitString :: Int -> [String]
makeBitString 0 = []
makeBitString 1 = ["0","1"]
makeBitString w = map ('0':) (makeBitString (w-1)) ++ map ('1':) (makeBitString (w-1))
makeMaskZeroString :: Int -> [String]
makeMaskZeroString w = ((map oneToMask) . makeBitString) w
where
oneToMask :: String -> String
oneToMask = (map (\c -> if c == '1' then '*' else c))