Skip to content

Instantly share code, notes, and snippets.

View maiyama18's full-sized avatar

maiyama maiyama18

View GitHub Profile
import SwiftUI
import OSLog
struct LogScreen: View {
enum SearchScope: Hashable {
case all
case category(LogCategory)
}
@State private var allLogEntries: [LogEntry] = []
import CoreData
import Combine
import Foundation
import Observation
@Observable
@MainActor
public final class CloudSyncState {
public enum SyncStatus {
case notStarted
import UIKit
struct Todo: Identifiable {
var id: UUID
var title: String
var done: Bool
}
final class TodoRepository {
private var todos: [Todo] = (1...30).map { i in
//
// Topic006.swift
// SwiftUIWeeklyLayoutChallenge
//
// Created by treastrain on 2022/08/17.
//
import SwiftUI
fileprivate func +(left: CGSize, right: CGSize) -> CGSize {
.init(width: left.width + right.width, height: left.height + right.height)
import UIKit
import Combine
enum MessageViewControllerFactory {
static func createDefaultImplementation() -> MessageViewController<MessageRepository<APIClient>> {
return MessageViewController(viewState: MessageViewState())
}
}
final class MessageViewController<Repository: MessageRepositoryProtocol>: UIViewController {
import SwiftUI
class Particle {
var position: CGPoint
var velocity: CGPoint
var color: Color
var size: CGFloat
init(position: CGPoint, velocity: CGPoint, color: Color, size: CGFloat) {
self.position = position
import SwiftUI
extension CGPoint {
func distance(to other: CGPoint) -> CGFloat {
let dx = self.x - other.x
let dy = self.y - other.y
return sqrt(dx * dx + dy * dy)
}
}
import SwiftUI
struct ContentView: View {
@State private var isImageViewerPresented: Bool = false
var body: some View {
VStack {
Button(action: {
withAnimation {
isImageViewerPresented = true
import WidgetKit
import SwiftUI
struct RandomNumberWidgetProvider: IntentTimelineProvider {
func placeholder(in context: Context) -> RandomNumberWidgetEntry {
RandomNumberWidgetEntry(date: Date(), number: 42)
}
func getSnapshot(for configuration: RandomNumberIntent, in context: Context, completion: @escaping (RandomNumberWidgetEntry) -> ()) {
let entry = RandomNumberWidgetEntry(date: Date(), number: getRandomNumber(configuration: configuration))
import WidgetKit
import SwiftUI
struct RandomNumberWidgetProvider: TimelineProvider {
func placeholder(in context: Context) -> RandomNumberWidgetEntry {
RandomNumberWidgetEntry(date: Date(), number: 42)
}
func getSnapshot(in context: Context, completion: @escaping (RandomNumberWidgetEntry) -> ()) {
let entry = RandomNumberWidgetEntry(date: Date(), number: getRandomNumber())