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 store<T: Codable>(values: [String: T]) { | |
// How do I check if *this* if nil? | |
let myVal = values["hello"] | |
print(myVal) // Optional(nil) | |
print(myVal == nil) // false | |
} | |
let point1: CGPoint? = nil | |
store(values: ["hello": point1]) |
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
struct MyWrapper { | |
let key: String | |
let value: any Codable | |
} | |
let point: CGPoint? = nil | |
let wrapper = MyWrapper(key: "point", value: point) | |
// ⚠️ Comparing non-optional type always returns false | |
// … but it IS nil :( |
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 catWorld = CatWorld.shared | |
var body: some View { | |
VStack { | |
Text("Value: \(catWorld.giveCat() ?? "No cat yet")") | |
Text("num: \(catWorld.number)") | |
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 WidgetKit | |
import SwiftUI | |
@main | |
struct WidgetExtMain { | |
static func main() { | |
if #available(iOS 18.0, *) { | |
MyWidgets_18.main() | |
} else { |
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
-- Make Sketch use the middle mouse button for dragging like Figma, Fusion 360, etc. | |
local middleMouseDown = false | |
-- Function to handle the middle mouse down event | |
local function middleMouseDownHandler(event) | |
if event:getType() == hs.eventtap.event.types.otherMouseDown then | |
if event:getProperty(hs.eventtap.event.properties['mouseEventButtonNumber']) == 2 then | |
middleMouseDown = true | |
-- Simulate holding down the space bar | |
hs.eventtap.event.newKeyEvent(hs.keycodes.map['space'], true):post() |
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 | |
import WebKit | |
@main | |
struct WebViewActingUpApp: App { | |
var body: some Scene { | |
WindowGroup(id: "Main") { | |
ContentView() | |
} |
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 | |
import WebKit | |
@main | |
struct WebViewActingUpApp: App { | |
var body: some Scene { | |
WindowGroup(id: "Main") { | |
ContentView() | |
} |
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 | |
@main | |
struct WindowPresentationFunApp: App { | |
@State var appState = AppState() | |
var body: some Scene { | |
WindowGroup { | |
RootView(appState: appState) | |
.onAppear { |
NewerOlder