Skip to content

Instantly share code, notes, and snippets.

@NeilsUltimateLab
NeilsUltimateLab / BackwardScrollView.swift
Last active February 17, 2022 13:58
A SwiftUI Scrollview container starts from right (horizontally) or bottom (vertically).
import SwiftUI
struct BackwardScrollView<V: View>: View {
var axis: Axis.Set = .horizontal
var content: ()->V
var leadingInset: CGFloat
init(_ axis: Axis.Set = .horizontal, leadingInset: CGFloat = 10, content: @escaping ()->V) {
self.axis = axis
@NeilsUltimateLab
NeilsUltimateLab / ImagePickerDisplaying+AppError.swift
Last active January 12, 2021 06:56
UIImagePicker protocol in SwiftUI with permission checks.
//
// AppError.swift
// ImagePickerDisplayer
//
// Created by Neil on 03/12/20.
//
import Foundation
enum AppError: Equatable, Error {
@NeilsUltimateLab
NeilsUltimateLab / OneTimeCodeField.swift
Last active June 23, 2022 16:18
One Time Code field without UITextFields hacks.
import UIKit
class OneTimeCodeField: UIControl {
enum FieldState {
case empty
case filled
case respoding
}
import UIKit
import MessageUI
struct MailInfo {
var recipient: String
var subject: String?
var message: String?
var isHTML: Bool = false
}
@NeilsUltimateLab
NeilsUltimateLab / MessageFieldView + AppTextView.swift
Created November 12, 2019 16:13
AutomaticSizing Message field to conversational screens.
class AppTextView: UITextView {
var onTextChange: ((String?)->Void)?
override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
observeTextChanges()
}
required init?(coder aDecoder: NSCoder) {
@NeilsUltimateLab
NeilsUltimateLab / UserDefaulter.swift
Created November 4, 2019 05:46
Property Wrapper for User Defaults.
@propertyWrapper
struct UserDefaulter<A: RawRepresentable> {
let key: String
init(_ key: String) {
self.key = key
}
private var fetchedValue: A?
var wrappedValue: A? {
mutating get {
@NeilsUltimateLab
NeilsUltimateLab / FetchingView.swift
Created October 25, 2019 03:20
Provide animation for Web Request States.
import UIKit
extension FetchingView {
enum State {
case fetching
case fetched
case error(ResponseError)
}
}
protocol ReusableView: class {
static var identifier: String { get }
}
extension ReusableView where Self: NSObject {
static var identifier: String {
return String(describing: self)
}
}
import UIKit
class IndicatorButton: UIButton {
private var indicatorView: UIActivityIndicatorView = {
let aiv = UIActivityIndicatorView(style: .white)
aiv.hidesWhenStopped = true
aiv.translatesAutoresizingMaskIntoConstraints = false
aiv.isUserInteractionEnabled = false
return aiv
class NotchView: UIView {
var notchWidth: CGFloat = 16
var notchHeight: CGFloat = 12
var cornerRadius: CGFloat = 8
override func awakeFromNib() {
super.awakeFromNib()
self.isUserInteractionEnabled = true
}