Skip to content

Instantly share code, notes, and snippets.

@tgnivekucn
tgnivekucn / ChatGPTGenerateSwiftUITest1.swift
Created April 11, 2023 21:05
ChatGPT Generate SwiftUI Test1
import SwiftUI
struct ContentView: View {
@State private var username: String = ""
@State private var password: String = ""
var body: some View {
VStack {
Spacer(minLength: 20)
@tgnivekucn
tgnivekucn / SwiftUILoginPage.swift
Created March 16, 2023 17:43
SwiftUI login page generated by bing chatGPT
import SwiftUI
struct LoginView: View {
@State private var username = ""
@State private var password = ""
var body: some View {
VStack {
Image("logo")
.resizable()
@tgnivekucn
tgnivekucn / SwiftUILoginPage2.swift
Created March 16, 2023 15:10
SwiftUI login page generated by ChatGPT
struct LoginPage: View {
@State private var username: String = ""
@State private var password: String = ""
var body: some View {
VStack {
Image("your_image_name_here")
.resizable()
.frame(width: 300, height: 300)
.padding(.top, 20)
@tgnivekucn
tgnivekucn / LoginPageUI.swift
Created March 16, 2023 05:53
SwiftUI login page UI
import SwiftUI
import Auth0
struct LoginView: View {
@State private var email = ""
@State private var password = ""
@State private var profile: UserInfo?
var body: some View {
VStack {
@tgnivekucn
tgnivekucn / observerPatternExample.swift
Created March 5, 2023 08:16
ObserverPatternInSwift
class Subject {
var list: [Adventurer] = []
func add(adventurer: Adventurer) {
list.append(adventurer)
}
func remove(adventurer: Adventurer) {
if let index = list.firstIndex(where: { $0 == adventurer}) {
list.remove(at: index)
}
@tgnivekucn
tgnivekucn / IOS_Swift_Message_Dispatch_with_closure.swift
Created January 4, 2023 09:08
IOS Swift message dispatch with closure
class DataModel: NSObject {
var data = 1
var callback: ((Any?) -> Unmanaged<AnyObject>?)?
}
class CustomClass: NSObject {
@objc func getValue(_ model: DataModel, completion callback: Any!) {
print("get Value for CustomClass")
@tgnivekucn
tgnivekucn / IOS_Swift_Message_Dispatch.swift
Created January 4, 2023 08:32
Swift messages dispatch
import Foundation
class CustomClass: NSObject {
@objc func getValue(_ arg: Int) {
print("val is: 100")
}
@objc func getValue2() {
print("val is: 2")
}
@tgnivekucn
tgnivekucn / SimulateRxSwift.swift
Created January 4, 2023 07:33
Simulate RxSwift
class DisposeBag {
var delegate: RxSimulator?
deinit {
print("test11 DisposeBag deinit")
delegate = nil
}
}
class RxSimulator {
@tgnivekucn
tgnivekucn / gist:1040e7ad3a044bb0fe32b86583b1cf67
Created December 13, 2022 10:40
Call a method from a String in Swift
// Ref: https://stackoverflow.com/questions/24245262/call-a-method-from-a-string-in-swift
import UIKit
class TestDevice1: NSObject {
@objc func getPressure() {
print("get Pressure for TestDevice1")
}
@objc func getBattery() {
print("get Battery for TestDevice1")
@tgnivekucn
tgnivekucn / FileOutputStream.swift
Created October 17, 2022 05:41
Buffered writing to a file with Swift OutputStreamType and GCD i/o channel (Original version in Objective-C: https://gist.github.com/algal/54467df650c875827f2b)
// Ref:
// https://gist.github.com/algal/54467df650c875827f2b
// https://developer.apple.com/documentation/dispatch/dispatchio/2892309-init
class FileOutputStream: OutputStream {
private var filepath: URL!
private var channel: DispatchIO!
// Initialized an output stream that writes to `filepath`.