This file contains 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 ContentView: View { | |
@State var showModal: Bool = false | |
var body: some View { | |
NavigationView { | |
VStack { | |
WebView(url: URL(string: "https://www.example.com")!) | |
Button("Fixme") { self.showModal = true } |
This file contains 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 Sample: View { | |
var body: some View { | |
NavigationView { | |
WebView(url: URL(string: "https://example.com")!) | |
.navigationBarItems( | |
trailing: Button( | |
action: { }, | |
label: { Text("Done") } |
This file contains 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
// Dumb value types representing UIViews. Comperable to our current models like Button.Model | |
struct StackView<Message> { | |
let children: [View<Message>] | |
} | |
struct Label { | |
let text: String | |
} |
This file contains 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
func assert(_ cond: @autoclosure () -> Bool) -> String { | |
if cond() { | |
return "✅" | |
} else { | |
return "❌" | |
} | |
} | |
#if !swift(>=4.2) | |
protocol KnownEnum: RawRepresentable, Hashable where RawValue == String { |
This file contains 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 Foundation | |
enum Message<T> { | |
case value(T) | |
case finished | |
} | |
protocol Channel: IteratorProtocol { | |
func send(_ value: Message<Element>) | |
} |
This file contains 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
// Returning a function here, instead of a fully realized object | |
extension Company: Decodable { | |
static func decode(j: JSON) -> Decoded<[People] -> Company> { | |
return create | |
<^> j <| "id" | |
<*> j <| ["attributes", "name"] | |
} | |
} |
This file contains 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
// stored property, no default value | |
let foo: String | |
// stored property, default value | |
let foo: String = "foo" | |
// or | |
let foo = "foo" | |
// computed property, no custom setter | |
var foo: String { |
This file contains 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
// Original implementation with multiple returns: | |
class func fromId(id: String) -> Office? { | |
let officesData = JSONData.load("offices") as? [[String: String]] ?? [] | |
let officeData = officesData.filter { $0["id"] == id }.first | |
if let office = officeData { | |
return decode(JSONValue.parse(office)) | |
} | |
This file contains 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 Argo | |
import Runes | |
func +<T, V>(lhs: [T: V], rhs: [T: V]) -> [T: V] { | |
var dict = lhs | |
for (key, val) in rhs { | |
dict[key] = val | |
} | |
return dict |
This file contains 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 Foundation | |
infix operator >>- { associativity left precedence 150 } | |
public func >>-<T, U>(a: T?, f: T -> U?) -> U? { | |
return a.flatMap(f) | |
} | |
extension Optional { | |
func flatMap<U>(f: T -> U?) -> U? { | |
switch self { |
NewerOlder