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 / MapViewView.swift
Last active November 1, 2021 07:14
Advanced Mapview view
import SwiftUI
import MapKit
struct ContentView: View {
// MARK: - Properties
@State private var centerCoordinate = CLLocationCoordinate2D()
@State private var locations = [MKPointAnnotation]()
@State private var selectedPlace: MKPointAnnotation?
@State private var showingPlaceDetails = false
@Rsych
Rsych / Mapview.swift
Last active November 1, 2021 07:15
Advanced MKMapView
import MapKit
import SwiftUI
struct MapView: UIViewRepresentable {
@Binding var centerCoordinate: CLLocationCoordinate2D
@Binding var selectedPlace: MKPointAnnotation?
@Binding var showingPlaceDetails: Bool
var annotations: [MKPointAnnotation]
class Coordinator: NSObject, MKMapViewDelegate {
struct BiometricAuth: View {
// MARK: - Properties
@State private var isUnlocked = false
// MARK: - Body
var body: some View {
VStack {
if isUnlocked {
Text("Unlocked")
} else {
@Rsych
Rsych / BiometricAuth1.swift
Created October 31, 2021 08:21
Biometric Authentication in SwiftUI
func authenticate() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "We need to unlock your data."
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authError in
DispatchQueue.main.async {
if success {
@Rsych
Rsych / MapView2.swift
Created October 31, 2021 07:07
Almost complete mapView struct
import MapKit
import SwiftUI
struct MapView: UIViewRepresentable {
class Coordinator: NSObject, MKMapViewDelegate {
var parent: MapView
init(_ parent: MapView) {
self.parent = parent
}
@Rsych
Rsych / MapView1.swift
Created October 31, 2021 06:46
Mapview 1
import MapKit
import SwiftUI
struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
let mapView = MKMapView()
return mapView
} //: makeUIView func
func updateUIView(_ view: MKMapView, context: Context) {
// MARK: - Body
var body: some View {
Group {
if loadingState == .loading {
LoadingView()
} else if loadingState == .success {
SuccessView()
} else if loadingState == .failed {
FailedView()
}
@Rsych
Rsych / EnumViews.swift
Created October 30, 2021 16:10
make views with state
struct LoadingView: View {
var body: some View {
Text("Loading...")
}
} //: LoadingView
struct SuccessView: View {
var body: some View {
Text("Success")
}
@Rsych
Rsych / EnumState.swift
Created October 30, 2021 16:10
make enum representing each view state
struct SwitchingViewEnums: View {
// MARK: - Properties
enum LoadingState {
case loading, success, failed
} //: View State enum
var loadingState = LoadingState.loading
@Rsych
Rsych / FilemanagerBundleBodyView.swift
Created October 30, 2021 16:03
Filemanager Bundle body
Text("Filemanager Bundle")
.onTapGesture {
let str2 = "Test 2"
let path2 = FileManager.default.documentDirectory().appendingPathComponent("message2.txt")
do {
try str2.write(to: path2, atomically: true, encoding: .utf8)
let input2 = try String(contentsOf: path2)
print(input2)
} catch {
print(error.localizedDescription)