Skip to content

Instantly share code, notes, and snippets.

final class NSRegex {
private let regex:NSRegularExpression
private let subject:String
private var matches:[NSTextCheckingResult] = []
init(regex:NSRegularExpression, subject:String) {
self.regex = regex
self.subject = subject
matches = regex.matches(in: subject, range: NSRange(location: 0, length: subject.count))
class AppDelegate {
func appDidFinishLaunching() {
//Before the app shows root view controller, check for an override style.
window = UIWindow()
if let override = UserDefaults.standard.bool(forKey: "OverrideStyle") {
//There was an override set, use that otherwise use the system appearance
window?.overrideUserInterfaceStyle = override ? .dark : .light
}
}
}
///Options that your UITextFieldDelegate or UITextViewDelegate can
///implement to provide some return key type options to the field navigator.
protocol FormFieldNavigationReturnKeyTypeOptions {
///Whether or not the field navigator can set return type.
var fieldNavigatorCanSetReturnKeyType:Bool { get set }
///The return key type that the field navigator should set.
var fieldNavigatorReturnKeyType:UIReturnKeyType? { get set }
class FormFieldNavigator {
//...
func update() {
guard let view = view else { return }
inputs = allInputs(view: view)
inputs.sort { view1, view2 in
let view1Frame = view1.convert(CGPoint.zero, to: nil)
let view2Frame = view2.convert(CGPoint.zero, to: nil)
#import <Foundation/Foundation.h>
@class PipedTaskRunner;
@protocol PipedTaskRunnerDelegate
@optional
- (void) taskRunner:(PipedTaskRunner *) taskRunner didReadData:(NSData *) data;
- (void) taskRunner:(PipedTaskRunner *) taskRunner didReadDataFromStdOut:(NSData *) data;
- (void) taskRunner:(PipedTaskRunner *) taskRunner didReadDataFromStdErr:(NSData *) data;
- (void) taskRunnerTerminated:(PipedTaskRunner *) taskRunner;
extension Notification.Name {
///Post this to go next.
static let FormFieldNavigationNext = Notification.Name("FormFieldNavigationNext")
///Post this to go previous.
static let FormFieldNavigationPrevious = Notification.Name("FormFieldNavigationPrevious")
///Post this to end editing.
static let FormFieldNavigationDone = Notification.Name("FormFieldNavigationDone")
extension Notification.Name {
///Post this to go next.
static let FormFieldNavigationNext = Notification.Name("FormFieldNavigationNext")
///Post this to go previous.
static let FormFieldNavigationPrevious = Notification.Name("FormFieldNavigationPrevious")
///Post this to end editing.
static let FormFieldNavigationDone = Notification.Name("FormFieldNavigationDone")
class FormFieldNavigator {
weak var view:UIView? {
didSet {
if let _ = view {
update()
} else {
inputs = []
}
}
inputs.sort { view1, view2 in
let view1Frame = view1.convert(CGPoint.zero, to: nil)
let view2Frame = view2.convert(CGPoint.zero, to: nil)
if view1Frame.y == view2Frame.y {
return view1Frame.x < view2Frame.x
}
return view1Frame.y < view2Frame.y
}
@gngrwzrd
gngrwzrd / allInputs.swift
Last active May 31, 2021 23:26
iOS Find All Inputs
private func allInputs(view:UIView) -> [UIView] {
var inputs:[UIView] = []
for view in view.subviews {
if view is UITextField || view is UITextView {
inputs.append(view)
}
let subInputs = _allInputs(view: view)
if subInputs.count > 0 {
inputs.append(contentsOf: subInputs)
}