Skip to content

Instantly share code, notes, and snippets.

@cenkbilgen
cenkbilgen / LongPressProgress.swift
Last active May 3, 2021 17:00
SwiftUI Long Press Progress View
// Using `.updating(...)` with a @GestureState seemed like the way to go
// but pressing state end update is not readily available
// standard `.onLongPress` modifier works best
struct LongPressExample: View {
let duration: TimeInterval
@State private var progress: CGFloat = 0
@State private var isDone = false
var body: some View {
@cenkbilgen
cenkbilgen / KeyboardObserver.swift
Last active March 29, 2021 18:41
SwiftUI EnvironmentObject for Keyboard Changes
import SwiftUI
import Combine
#if os(iOS)
import UIKit.UIResponder
#endif
class KeyboardObserver: ObservableObject {
struct State: Equatable {
let frame: CGRect
let isLocal: Bool // on multitasking iPad apps, all visible apps notified
@cenkbilgen
cenkbilgen / URLSessionDownloadPublisher.swift
Created February 26, 2020 20:52
An extension to URLSession to create a Combine Publisher for URLDownloadTask
import Foundation
import Combine
fileprivate class CancellableStore {
static let shared = CancellableStore()
var cancellables = Set<AnyCancellable>()
}
public enum DownloadOutput {
case complete(Data)
@cenkbilgen
cenkbilgen / gist:8318a0675af4cfa01fd89e15976eb587
Last active January 13, 2020 20:38
Swift Playground for Publishers using Merge, CombineLatest & Zip
import Foundation
import Combine
var count = 0
enum Marker: CustomDebugStringConvertible {
case A(Int)
case B(Int)
var debugDescription: String {
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {
@cenkbilgen
cenkbilgen / EnvironmentVariables.swift
Last active October 27, 2019 18:38
Extension for SwiftUI that reports the current keyboard height to Views through an EnvironmentVariable (modify to report any other notification).
//
// EnvironmentVariables.swift
// PlaylogR
//
// Created by Cenk Bilgen on 2019-10-12.
// Copyright © 2019 Cenk Bilgen. All rights reserved.
//
import SwiftUI
import UIKit
@cenkbilgen
cenkbilgen / Origin.swift
Created March 12, 2019 17:38
A SceneKit node showing the world origin and axis directions. Helpful in ARKit, to know where exactly the session started and relative node locations.
//
// OriginAxis.swift
//
// Created by abc on 2019-03-07.
// Copyright © 2019 Cenk Bilgen. All rights reserved.
//
import Foundation
import SceneKit
@cenkbilgen
cenkbilgen / URLRequestExtension.swift
Created January 30, 2019 23:23
"multipart/form-data" in Swift
//
// URLRequestExtension.swift
//
// Created by Cenk Bilgen on 2019-01-30.
// Copyright © 2019 abc. All rights reserved.
//
import Foundation
extension URLRequest {
@cenkbilgen
cenkbilgen / gist:f5d04bbbc11520329f733816944ef914
Created October 30, 2018 17:06
A simple GraphQL Search and Query generator and fetcher in one Swift file
//
// GraphQL.swift
//
// Created by Cenk Bilgen on 2018-10-15.
// Copyright © 2018 Cenk Bilgen. All rights reserved.
//
import Foundation
// Generate a simple GraphQL search based query