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
struct GesturesUse: View {
// MARK: - Properties
@State private var currentAmount: CGFloat = 0
@State private var finalAmount: CGFloat = 1
@State private var currentAngle: Angle = .degrees(0)
@State private var finalAngle: Angle = .degrees(0)
// MARK: - body
var body: some View {
VStack {
@Rsych
Rsych / Prospect.swift
Created November 5, 2021 13:52
Saving and loading data with UserDefaults
import SwiftUI
class Prospect: Identifiable, Codable {
var id = UUID()
var name = "Anonymous"
var emailAddress = ""
fileprivate(set) var isContacted = false
}
@Rsych
Rsych / QRCodeGenerator.swift
Created November 5, 2021 12:58
QRCode Generator
import SwiftUI
import CoreImage.CIFilterBuiltins
struct MeView: View {
// MARK: - Properties
@State private var name = ""
@State private var emailAddress = ""
let context = CIContext()
import SwiftUI
struct ContentView: View {
// MARK: - Properties
@State private var selectedTab = 0
// MARK: - Body
var body: some View {
TabView(selection: $selectedTab) {
ProspectsView(filter: .none)
.tabItem {
@Rsych
Rsych / TabviewEnum.swift
Created November 5, 2021 11:53
Tabview with enum casing
import SwiftUI
struct ProspectsView: View {
// MARK: - Properties
enum FilterType {
case none, contacted, uncontacted
} //: Filtertype enum
let filter: FilterType
import SwiftUI
import UserNotifications
struct SchedulingLocalNotifications: View {
// MARK: - Properties
// MARK: - Body
var body: some View {
VStack {
Button {
struct CreateContextMenu: View {
// MARK: - Properties
@State private var backgroundColor = Color.red
// MARK: - Body
var body: some View {
VStack {
Text("Hello, World!")
.padding()
.background(backgroundColor)
// MARK: - Body
var body: some View {
Text("Hello World")
.onAppear {
fetchData(from: "https://www.apple.com") { result in
switch result {
case .success(let str):
// print(str)
print("success")
case .failure(let error):
@Rsych
Rsych / fetchData.swift
Created November 4, 2021 07:31
fetch data with enum cases
func fetchData(from urlString: String, completion: @escaping (Result<String, NetworkError>) -> Void) {
// check if url is ok else return failure
guard let url = URL(string: urlString) else {
completion(.failure(.badURL))
return
}
URLSession.shared.dataTask(with: url) { data, response, error in
DispatchQueue.main.async {
if let data = data {
// if we're here everything worked
@Rsych
Rsych / EnvironmentContent.swift
Created November 4, 2021 06:59
Reading custom values from environment
struct ContentView: View {
// MARK: - Properties
let user = User()
// MARK: - Body
var body: some View {
VStack {
EditView()
DisplayView()
}
.environmentObject(user)