Skip to content

Instantly share code, notes, and snippets.

import SwiftUI
struct ContentView: View {
var body: some View {
Slidey()
}
}
struct Slidey: View {
let width: CGFloat = 200.0
import SwiftUI
struct ContentView: View {
@State var x: CGFloat = -1.0
var body: some View {
VStack(spacing: 50.0) {
Text("\(Int(x))")
RoundedRectangle(cornerRadius: 20.0)

I have a view model with two properties, a number and a selection. The number is updated once per second and shown on screen.

Beside that on the screen, is a Menu that displays the selection on click. But even though the Menu selection is not updated/affected once per second, the number is, and that seems to break the Menu's highlight state. In fact, it happens even if I put the selection in a separate object all together.

Why is this? How do I make SwiftUI more selective in only updating what's relevant?

struct ContentView: View {
    @State var viewModel = ViewModel(number: 111_111, animal: "Horse")
    
import SwiftUI
struct ContentView: View {
@State var viewModel = CoolViewModel()
var body: some View {
VStack {
Menu {
Picker("Ice Cream", selection: $viewModel.selectedIceCream) {
if let iceCreams = viewModel.iceCreams {
import SwiftUI
struct ContentView: View {
var viewModel = CoolViewModel()
var body: some View {
VStack {
Menu {
Picker("Ice Cream", selection: $viewModel.selectedIceCream) {
ForEach(viewModel.iceCreams) { iceCream in
@christianselig
christianselig / right_pcb.yaml
Created November 16, 2023 04:10
Ergogen right split keyboard PCB config
right:
outlines:
main:
outline: board_right
footprints:
choc_hotswap:
what: choc
where: /^mirror_matrix_.*/
params:
keycaps: true
struct SoundMakerIntent: AudioPlaybackIntent {
static var title: LocalizedStringResource = "Play a sound"
static var description: IntentDescription = IntentDescription("Plays a widget sound")
@Parameter(title: "Sound")
var sound: WidgetSound
init() {}
init(sound: WidgetSound) {
@christianselig
christianselig / widget-center-async-await.swift
Created August 10, 2023 23:39
Adds async await support to WidgetCenter configuration fetch
import WidgetKit
extension WidgetCenter {
func currentConfigurations() async throws -> [WidgetInfo] {
try await withCheckedThrowingContinuation { continuation in
getCurrentConfigurations { result in
continuation.resume(with: result)
}
}
}
@christianselig
christianselig / apollo-table.swift
Created August 1, 2023 15:28
Apollo Markdown table implementation
mutating func visitTable(_ table: Table) -> NSAttributedString {
let result = NSMutableAttributedString()
for child in table.children {
result.append(visit(child))
}
if table.hasValidSuccessor(parseTablesInline: parseTablesInline) {
result.append(.doubleNewline(withFontSize: FontManager.shared.regularFont().pointSize))
}
@christianselig
christianselig / apollo-update-june-19-2023.md
Last active October 2, 2023 22:00
I want to debunk Reddit's claims, and talk about their unwillingness to work with developers, moderators, and the larger community, as well as say thank you for all the support

I wanted to address Reddit's continued, provably false statements, as well as answer some questions from the community, and also just say thanks.

(Before beginning, to the uninitiated, "the Reddit API" is just how apps and tools talk with Reddit to get posts in a subreddit, comments on a post, upvote, reply, etc.)

Reddit: "Developers don't want to pay"

Steve Huffman on June 15th: "These people who are mad, they’re mad because they used to get something for free, and now it’s going to be not free. And that free comes at the expense of our other users and our business. That’s what this is about. It can’t be free."

This is the false argument Steve Huffman keeps repeating the most. Developers are very happy to pay. Why? Reddit has many APIs (like voting in polls, Reddit Chat, view counts, etc.) that they haven't made available to developers, and a more formal relationship with Reddit has the opportunity to create a better API experience with more features available. I expressed this willingness to pay m