Skip to content

Instantly share code, notes, and snippets.

Jasper Haggenburg Jpunt

Block or report user

Report or block Jpunt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Optionals in Swift UI - 8.swift
var body: some View {
List(tweets.identified(by: \.id)) { tweet in
HStack {
Text(tweet.message)
tweet.imageName.map
{ ViewBuilder.buildEither(first: Image($0) }
?? ViewBuilder.buildEither(second: Text("No image"))
}
}
View Optionals in Swift UI - 7.swift
var body: some View {
List(tweets.identified(by: \.id)) { tweet in
HStack {
Text(tweet.message)
tweet.imageName.map { Image($0) } ?? Image("fallback")
}
}
}
View Optionals in Swift UI - 6.swift
var body: some View {
List(tweets.identified(by: \.id)) { tweet in
HStack {
Text(tweet.message)
tweet.imageName.map { Image($0) }
}
}
}
View Optionals in Swift UI - 5.swift
var body: some View {
List(tweets.identified(by: \.id)) { tweet in
HStack {
Text(tweet.message)
IfLet(tweet.imageName) { imageName in
Image(imageName)
}
}
}
View Optionals in Swift UI - 4.swift
struct IfLet<T, Out: View>: View {
let value: T?
let produce: (T) -> Out
init(_ value: T?, produce: @escaping (T) -> Out) {
self.value = value
self.produce = produce
}
var body: some View {
View Optionals in Swift UI - 3.swift
var body: some View {
Group {
if x {
Text(“Something”)
} else {
Text(“Something else”)
}
}
}
View Optionals in Swift UI - 2.swift
var body: some View {
Group {
Text(“First thing”)
Text(“Second thing”)
Text(“Third thing”)
}
}
View Optionals in Swift UI - 1.swift
import SwiftUI
struct Tweet: Identifiable {
var id: UUID
let message: String
let imageName: String?
init(message: String, imageName: String? = nil) {
self.id = UUID()
self.message = message
@Jpunt
Jpunt / redux.ts
Last active Oct 4, 2018
This is how I like to do Redux stuff in TypeScript. Good coverage, with minimal effort and redefining types. What do you think?
View redux.ts
/**
* Types
*/
// IState
import rootReducer from "./reducers";
export type IState = {
// Maps the return type of each reducer into its return-type
[K in keyof typeof rootReducer]: ReturnType<typeof rootReducer[K]>
}
@Jpunt
Jpunt / btt-toggle-appearance.json
Created Sep 25, 2018
BetterTouchTool: Toggle Mojave appearance on the Touch Bar
View btt-toggle-appearance.json
{
"BTTWidgetName" : "Toggle appearance",
"BTTTriggerType" : 639,
"BTTTriggerTypeDescription" : "Apple Script Widget",
"BTTTriggerClass" : "BTTTriggerTypeTouchBar",
"BTTPredefinedActionType" : 195,
"BTTPredefinedActionName" : "Run Apple Script (async in background)",
"BTTInlineAppleScript" : "tell application \"System Events\"\r\ttell appearance preferences\r\t\tset dark mode to not dark mode\r\tend tell\rend tell",
"BTTEnabled2" : 1,
"BTTUUID" : "ECC2514E-86E5-4304-AABA-BA7749257FDC",
You can’t perform that action at this time.