I hereby claim:
- I am klundberg on github.
- I am kevlario (https://keybase.io/kevlario) on keybase.
- I have a public key ASAXKidIohQbWt66-UXKy-Ek8vejycrMu6F4xoG3oojvTQo
To claim this, I am signing this object:
// these functions take a swift class's statically referenced method and the instance those methods | |
// should apply to, and returns a function that weakly captures the instance so that you don't have | |
// to worry about memory retain cycles if you want to directly use an instance method as a handler | |
// for some object, like NSNotificationCenter. | |
// | |
// For more information, see this post: | |
// http://www.klundberg.com/blog/capturing-objects-weakly-in-instance-method-references-in-swift/ | |
func weakify <T: AnyObject, U>(owner: T, f: T->U->()) -> U -> () { | |
return { [weak owner] obj in |
import UIKit | |
class ViewController: UIViewController { | |
// error: 'UISearchController' is only available on iOS 8.0 or newer | |
var searchController: UISearchController? | |
// error: Stored properties cannot be marked potentially unavailable with 'introduced=' | |
@available(iOS 8.0, *) | |
var conditionallyAvailableSearchController: UISearchController? |
struct TableViewSection<T, Cell: UITableViewCell> { | |
var cellIdentifier: String = "" | |
var items: [T] = [] | |
var configureCell: (cell: Cell, item: T, indexPath: NSIndexPath) -> Void | |
} | |
class TableViewDataSource: NSObject, UITableViewDataSource { | |
var sections: [TableViewSection<?, ?>] = [] // I want arbitrary T/Cell types here, what do? | |
// ... |
protocol BaseSection { | |
var cellIdentifier: String { get } | |
func numberOfRows() -> Int | |
func registerIdentifier(tableView: UITableView) | |
func configureCell(cell: UITableViewCell, indexPath: NSIndexPath) | |
} | |
class Section<T, Cell: UITableViewCell>: BaseSection { | |
var rows: [T] = [] | |
var cellIdentifier = "" |
let regex = try NSRegularExpression(pattern: mypattern, options: []) | |
let str = "some string to match" | |
if let result = regex.firstMatchInString(str, options: [], range: NSMakeRange(0, str.characters.count)) { | |
print((str as NSString).substringWithRange((result?.rangeAtIndex(1))!)) | |
} |
I hereby claim:
To claim this, I am signing this object:
// Written using Swift 3.0.x | |
fileprivate final class Box<T> { | |
let unbox: T | |
init(_ value: T) { | |
unbox = value | |
} | |
} | |
public struct CopyOnWrite<T: AnyObject> { |
/usr/bin/xcrun xcodebuild -workspace /Users/klundberg/workspaces/wayfair-ios/Carthage/Checkouts/FutureKit/FutureKit.xcworkspace -scheme FutureKit\ iOS -configuration Release -derivedDataPath /Users/klundberg/Library/Caches/org.carthage.CarthageKit/DerivedData/FutureKit/3.0.0 -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean buildUser defaults from command line: | |
IDEDerivedDataPathOverride = /Users/klundberg/Library/Caches/org.carthage.CarthageKit/DerivedData/FutureKit/3.0.0 | |
Build settings from command line: | |
BITCODE_GENERATION_MODE = bitcode | |
CARTHAGE = YES | |
CODE_SIGN_IDENTITY = | |
CODE_SIGNING_REQUIRED = NO | |
ONLY_ACTIVE_ARCH = NO | |
SDKROOT = iphoneos11.0 |
{% for type in types.based.Codable|!enum %} | |
public extension {{ type.name }} { | |
enum CodingKeys: String, CodingKey { | |
{% for variable in type.variables|instance %} | |
{% if variable|annotated:"keyOverride" %} | |
case {{ variable.name }} = "{{ variable.annotations.keyOverride }}" | |
{% else %} | |
case {{ variable.name }} = "{{ variable.name|camelToSnakeCase }}" | |
{% endif %} | |
{% endfor %} |
enum JSONValue: Codable, Equatable { | |
struct JSONValueDecodingError: Error { | |
let message: String | |
} | |
case boolean(Bool) | |
case number(Double) | |
case string(String) | |
case array([JSONValue?]) | |
case object([String: JSONValue?]) |