This file contains hidden or 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 | |
// 【SwiftUI】TextField の角を丸くして背景色を付けるもっとも簡単な方法は | |
// https://android.benigumo.com/20240507/rounded-text-field/ | |
struct TestTextField: View { | |
@State private var text = "" | |
// style | |
// background |
This file contains hidden or 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 | |
// https://forums.developer.apple.com/forums/thread/736226 | |
struct TestModelActorView: View { | |
@Environment(\.modelContext) private var modelContext | |
// private var dataSource: DataSource { |
This file contains hidden or 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 | |
@ModelActor | |
actor LocalData { | |
nonisolated(unsafe) private(set) static var shared: LocalData! // * | |
private var task: Task<Void, Never>? | |
static func createInstance(modelContainer: ModelContainer) { // * |
This file contains hidden or 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 TestView: View { | |
@State private var text = "-" | |
private let url = URL(string: "https://wttr.in/?format=3")! | |
//private let url = URL(string: "https://httpbin.org/get")! | |
var body: some View { | |
Text(text) | |
.task { |
This file contains hidden or 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 TestObservable: View { | |
private var requester = Requester() | |
var body: some View { | |
VStack { | |
Text("\(requester.responseCode)") | |
Text("\(requester.responseBody)") | |
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 { |