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 { | |
@StateObject var service = ChatGPTService() | |
@State var textResponse = "" | |
var body: some View { | |
VStack { | |
Text("Bot says: \(textResponse)") | |
Button { | |
Task { |
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 Charts | |
import Combine | |
import Foundation | |
final class GameState: ObservableObject { | |
struct Player { | |
var position: Int | |
var halfSize: Int = 150 |
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
JSON: | |
https://unpkg.com/[email protected]/emoji.json | |
class EmojiManager: ObservableObject { | |
@Published var emojis: [EmojiObject] = [] | |
init() { | |
decodeJSON() |
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
private struct OnFirstAppear: ViewModifier { | |
let perform: () -> Void | |
let `else`: () -> Void | |
@State private var firstTime = true | |
func body(content: Content) -> some View { | |
content.onAppear { | |
if firstTime { | |
firstTime = false |
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
/// After reading an article from Antoine v.d. SwiftLee @twannl about conditional view modifier, I had an idea to improve my code I write for specific OS. | |
/// https://www.avanderlee.com/swiftui/conditional-view-modifier | |
extension Bool { | |
static var iOS: Bool { | |
#if os(iOS) | |
return true | |
#else | |
return false | |
#endif |
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
// | |
// SparkleCommands.swift | |
// Past for iChat | |
// | |
// Created by Helge Heß on 08.04.21. | |
// | |
import SwiftUI | |
#if SPARKLE && canImport(Sparkle) |
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
.onDrop(of: [.fileURL], isTargeted: nil) { providers in | |
if let loadableProvider = providers.first(where: { $0.canLoadObject(ofClass: URL.self) }) { | |
_ = loadableProvider.loadObject(ofClass: URL.self) { fileURL, _ in | |
if let fileURL = fileURL, fileURL.pathExtension.lowercased() == "zip" { | |
self.logger.info("Dropped \(fileURL.path)") | |
DispatchQueue.main.async { | |
importer.open(zipArchiveURL: fileURL) | |
} | |
} | |
} |
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
// | |
// KeyCommand.swift | |
// Adds Keyboard Shortcuts to SwiftUI on iOS 13 | |
// See https://steipete.com/posts/fixing-keyboardshortcut-in-swiftui/ | |
// License: MIT | |
// | |
// Usage: (wrap view in `KeyboardEnabledHostingController`) | |
// Button(action: { | |
// print("Button Tapped!!") | |
// }) { |
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 ContentView: View { | |
var body: some View { | |
Image(nsImage: NSImage(named: .init(NSImage.applicationIconName))!) | |
.resizable() | |
.frame(width: 100, height: 100) | |
.tapWithHighlight(onTap: { | |
print("Tap") | |
}, onLongPress: { | |
print("Long Press") | |
}) |
NewerOlder