Override stupid system default that disables state restoration.
UserDefaults.standard.set(true, forKey: "NSQuitAlwaysKeepsWindows") // override stupid global preference, so our state restore works properly
import Swift | |
public struct BinaryHeap<Element> { | |
public typealias Index = Int | |
var storage: [Element] | |
let comparator: (Element, Element) -> Bool | |
public var count: Int { | |
storage.count |
private func fetchAllUsers() -> SignalProducer<[User], Error> { | |
let decoder = JSONDecoder() | |
decoder.keyDecodingStrategy = .convertFromSnakeCase | |
func fetchUsers(since lastSeenUserID: Int?) -> SignalProducer<[User], Error> { | |
var components = URLComponents(string: "https://api.github.com/users")! | |
if let userID = lastSeenUserID { | |
components.queryItems = [ | |
URLQueryItem(name: "since", value: userID.description) |
// | |
// Generated by class-dump 3.5 (64 bit). | |
// | |
// class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2013 by Steve Nygard. | |
// | |
#pragma mark Blocks | |
typedef void (^CDUnknownBlockType)(void); // return type and parameters are unknown |
struct L10n { | |
struct Login { | |
static func welcomeMessage(placeholder: String) -> String { | |
return String.localizedStringWithFormat( | |
NSLocalizedString("login.welcome_message", "Greeting to show users upon successful login"), | |
placeholder | |
) | |
} | |
} | |
} |
extension NSColor { | |
// Derived from logic in TextMate | |
func soften(color inColor: NSColor, factor: CGFloat) -> NSColor { | |
guard let color = inColor.usingColorSpace(NSColorSpace.sRGB) else { | |
return inColor | |
} | |
var red = color.redComponent | |
var green = color.greenComponent | |
var blue = color.blueComponent |
Override stupid system default that disables state restoration.
UserDefaults.standard.set(true, forKey: "NSQuitAlwaysKeepsWindows") // override stupid global preference, so our state restore works properly
Adding "ownership" to Swift is a major feature with many benefits for programmers. This document is both a "manifesto" and a "meta-proposal" for ownership: it lays out the basic goals of the work, describes a general approach for achieving those goals, and proposes a number of specific changes and features, each of which will need to be separately discussed in a smaller and more
// Retry with backoff | |
// Adapted from http://blog.danlew.net/2016/01/25/rxjavas-repeatwhen-and-retrywhen-explained/ | |
Observable | |
.range(start: 1, count: 10) | |
.doOn(onNext: { i in | |
if i == 5 { | |
throw NSError(domain: "com.example", code: 1, userInfo: ["any": "thing"]) | |
} | |
}) | |
.retryWhen { (attempts: Observable<ErrorType>) -> Observable<Int64> in |
// FROM: http://ankit.im/swift/2016/01/18/first-pure-swift-ios-app-swiflytics/ | |
protocol StoryboardInstantiable { | |
typealias ViewController | |
static var storyboardID: String { get } | |
static func instance(storyboard: UIStoryboard) -> ViewController? | |
} | |
extension StoryboardInstantiable { | |
static func instance(storyboard: UIStoryboard) -> ViewController? { | |
return storyboard.instantiateViewControllerWithIdentifier(Self.storyboardID) as? ViewController |
@interface TSGraph : NSObject | |
- (void)addEdgeFrom:(id)vertexA to:(id)vertexB; | |
@end | |
@implementation TSGraph | |
{ | |
NSMutableDictionary *_vertices; | |
} |