Skip to content

Instantly share code, notes, and snippets.

View Rsych's full-sized avatar
🙈
I may be slow to respond.

J. W. Kim Rsych

🙈
I may be slow to respond.
View GitHub Profile
@Rsych
Rsych / BindingAlertAndSheet.swift
Created November 16, 2021 05:13
Binding alert and sheet
import SwiftUI
struct User: Identifiable {
var id = "Ryan"
}
struct BindingAlertAndSheet: View {
// MARK: - Properties
@State private var isShowingAlert = false
@State private var selectedUser: User? = nil
@Rsych
Rsych / OptionalAlertAndSheet.swift
Created November 16, 2021 05:12
Optional alert and sheet
import SwiftUI
struct User: Identifiable {
var id = "Ryan"
}
struct OptionalAlertAndSheet: View {
// MARK: - Properties
@State private var selectedUser: User? = nil
@Rsych
Rsych / SplitSideViews.swift
Created November 16, 2021 04:54
Split Side Views
struct SplitSideViews: View {
// MARK: - Properties
// MARK: - Body
var body: some View {
NavigationView {
NavigationLink(destination: Text("New secondary")) {
Text("Hello, World!")
} //: NavLink
.navigationTitle("Primary")
@Rsych
Rsych / CoverFlowScrollView.swift
Created November 15, 2021 12:13
CoverFlow ScrollView
struct CoverFlowScrollView: View {
// MARK: - Properties
let colors: [Color] = [.red, .green, .blue, .orange, .pink, .purple, .yellow]
// MARK: - Body
var body: some View {
VStack {
Spacer()
GeometryReader { fullView in
ScrollView(.horizontal, showsIndicators: false) {
HStack {
@Rsych
Rsych / ScrollViewDNAEffect.swift
Created November 15, 2021 11:41
ScrollView DNA alike effect
struct ScrollViewDNAEffect: View {
// MARK: - Properties
let colors: [Color] = [.red, .green, .blue, .orange, .pink, .purple, .yellow]
// MARK: - Body
var body: some View {
GeometryReader { fullView in
ScrollView(.vertical) {
ForEach(0..<50) { index in
GeometryReader { geo in
Text("Row #\(index)")
import SwiftUI
struct Card: Codable {
let prompt: String
var answer: String
}
struct EditCards: View {
// MARK: - Properties
@Environment(\.presentationMode) var presentationMode
@State private var cards = [Card]()
import SwiftUI
struct NotifiedBackground: View {
var body: some View {
/*
UIApplication.significantTimeChangeNotification is called when the user changes their clock or when daylight savings time changes.
UIResponder.keyboardDidShowNotification is called when the keyboard is shown.
*/
// Text("Hello, World!")
// .onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in
import SwiftUI
struct TriggerTimer: View {
// MARK: - Properties
// MARK: - Timer
/*
1. timer to fire every 1sec
2. timer should run on the main thread
3. timer should run on the common run loop. (Run loops lets iOS handle running code while the user is actively doing something, such as scrolling in a list.)
import CoreHaptics
import SwiftUI
struct VibrationsCoreHaptics: View {
// MARK: - Properties
@State private var engine: CHHapticEngine?
var body: some View {
Text("Tap here")
.onAppear(perform: prepareHaptics)
.onTapGesture(perform: complexSuccess)
@Rsych
Rsych / DraggingObj.swift
Created November 7, 2021 09:00
Dragging objects in swiftui
import SwiftUI
struct GestureDrag: View {
// MARK: - Properties
@State private var offset = CGSize.zero
@State private var isDragging = false
// MARK: - body
var body: some View {
let dragGesture = DragGesture()