Skip to content

Instantly share code, notes, and snippets.

@ZalyalovIldar
ZalyalovIldar / UITextField+Mask.swift
Last active January 23, 2024 17:44 — forked from andrealufino/UITextField+Mask.swift
Adding Mask to a TextField | Swift 4, GCD | + Static Prefix if need.
/// Usage: phoneTextField.formatPattern(pattern: "(***) ***-**-**", replacementChar: "*", staticPrefixString: "+7 ", allowText: false, allowNumbers: true)
extension UITextField {
/// Структура с перечислениями не хранимых полей
private struct FieldMaskProperties {
static var pattern = "pattern"
static var replacementChar = "replacementChar"
/// Timer that can work in background and update timer count if needed even if app resign active
class RepeatingTimer {
fileprivate enum State {
case suspended
case resumed
}
let timeInterval: TimeInterval
@ZalyalovIldar
ZalyalovIldar / RealmCascadeDelete
Created February 26, 2019 10:51
Realm Cascade delete
/// Cascade delete object in Realm
///
/// - warning: Call only in write transaction
/// - Parameters:
/// - object: Object to delete
/// - realm: Realm instance
/// - onlyProperties: removeOnly property (ex. before re-write/update model)
func cascadeDelete(_ object: Object, with realm: Realm, onlyProperties: Bool = false) {
protocol CurrentUserManager {
var currentUser: User { get }
}
class CurrentUserManagerIml: CurrentUserManager {
/// Current user cached in memory
/// obtainCurrentUser - static method, obtain User model from data base/file/e.t.c.
private static var currentUser: User = obtainCurrentUser()