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 SwiftData | |
@MainActor @Observable | |
final class LargeData { | |
var loadedItems: [Item] = [] | |
var count = 0 | |
private var modelContext: ModelContext! | |
private var predicate: Predicate<Item>! |
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 SwiftData | |
@Model | |
final class Item { | |
var i: Int | |
var s: String | |
init(i: Int, s: String) { | |
self.i = i |
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
let url = URL(string: "https://httpbin.org/anything/{anything}")! | |
let session = URLSession.shared | |
Task { | |
let (data, response) = try await URLSession.shared.data(from: url) | |
print((response as! HTTPURLResponse).statusCode) | |
print(String(data: data, encoding: .utf8)!) | |
// 200 |
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
// with: | |
// FileManageExtensions.swift | |
// https://gist.github.com/benigumocom/6a8e4506438b5260469c12b1c12c0fb7 | |
do { | |
let documents = URL.documentsDirectory | |
let text = "あいうえお" | |
// convert to data bytes | |
print( |
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
extension URL { | |
var exists: Bool { | |
isFile || isDirectory | |
} | |
var isFile: Bool { | |
(try? resourceValues(forKeys: [.isRegularFileKey]))?.isRegularFile == true | |
} | |
var isDirectory: Bool { |
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
extension URL { | |
// private var resourceIsDirectory: Bool? { | |
// (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory | |
// } | |
var exists: Bool { | |
// resourceIsDirectory != nil | |
// (try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory != nil | |
// (try? resourceValues(forKeys: [.isRegularFileKey]))?.isRegularFile != nil | |
isFile || isDirectory |
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 Chart: View { | |
var function: (Double) -> Double | |
var by: Double | |
private let height = 20.0 | |
private var data: [Double] { | |
stride(from: -3.0, to: 3.0 + by , by: by) |
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 TestColorValues: View { | |
var color: Color | |
@Environment(\.self) private var environment | |
private var resolved: Color.Resolved { | |
color.resolve(in: environment) | |
} |
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 TestDragGesture: View { | |
@State private var location = CGPoint(x: 150, y: 150) | |
@State private var startLocation: CGPoint? | |
var body: some View { | |
Circle() | |
.fill(.orange) | |
.frame(width: 200) |
NewerOlder