This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Cursor: Equatable { | |
let ns: NSCursor? | |
let id: String | |
} | |
struct CursorPreference: PreferenceKey { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
// Animates nicely since the type of both returns are the same, i.e. AnyView<Text> | |
func gimme(toggle: Bool) -> AnyView { | |
if toggle { | |
return AnyView( | |
Text("Hello World") | |
) | |
} else { | |
return AnyView( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let data = try Data(contentsOf: fileUrl) | |
let portraitMatteImage = CIImage(data: data, options: [.auxiliaryPortraitEffectsMatte: true]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
MIT License | |
Copyright 2018 Tobias Due Munk | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Sequence { | |
func map<T>(_ keyPath: KeyPath<Element, T>) -> [T] { | |
return self.map { | |
$0[keyPath: keyPath] | |
} | |
} | |
func flatMap<T>(_ keyPath: KeyPath<Element, T?>) -> [T] { | |
return self.flatMap { | |
$0[keyPath: keyPath] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class View: UIView { | |
override var intrinsicContentSize: CGSize { | |
// Fallback to super class implementation of intrinsicContentSize | |
return viewContentSize() ?? super.intrinsicContentSize | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias EmptyResult = () throws -> () | |
typealias AsyncResult = (EmptyResult) -> () | |
typealias JsonResult = () throws -> JSON | |
typealias AsyncJsonResult = (JsonResult) -> () | |
class GetResponse { | |
func main() { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mainQueueA = dispatch_get_global_queue(qos_class_main(), 0) | |
let mainQueueB = dispatch_get_main_queue() | |
// This works fine | |
dispatch_apply(3, mainQueueA) { i in | |
println("A: \(i)") | |
} | |
println("Yep") | |
// This never calls the block and hangs the main thread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AutoLayout.swift | |
// Tobias Due Munk | |
// | |
// Created by Tobias Due Munk on 26/08/14. | |
// Copyright (c) 2014 Tobias Due Munk. All rights reserved. | |
// | |
// Example usage: | |
// | |
// view1.topInset(20, relation: .Equal, priority: 200) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool { | |
window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
if let window = window { |
NewerOlder