This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
/* | |
Destructuring is the practice of pulling a tuple apart into multiple values in a single assignment. | |
*/ | |
// MARK: - Destructuring | |
extension String { | |
var splittedName: (String, String) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
final class Increment { | |
// MARK: - Properties | |
private var number: Int = 0 | |
// MARK: - This will cause memory leak | |
// lazy var incrementNumber: (Int) -> Void = { value in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Firebase | |
struct RemoteConfigModel { | |
var url: String? | |
var forceUpdate: String? | |
var version: String? | |
} | |
final class RemoteConfigManager { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
final class ViewController: UIViewController { | |
// Step 1 | |
lazy private var draggableView: UIView = { | |
let view = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 50, height: 50))) | |
view.backgroundColor = .red | |
return view |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import UIKit | |
public class ScannerOverlayPreviewLayer: AVCaptureVideoPreviewLayer { | |
// MARK: - OverlayScannerPreviewLayer | |
public var cornerLength: CGFloat = 30 | |
public var lineWidth: CGFloat = 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension Sequence { | |
func group<K: Hashable & Comparable>(by keyForValue: (Element) -> K) -> [[Element]] { | |
return Dictionary(grouping: self, by: keyForValue).sorted { $0.key < $1.key }.map { $0.value } | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol Buildable { } | |
public extension Buildable where Self: AnyObject { | |
func with<T>( | |
_ property: ReferenceWritableKeyPath<Self, T>, | |
_ value: T | |
) -> Self { | |
self[keyPath: property] = value | |
return self | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var email = "[email protected]" | |
var pattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | |
// Using NSPredicate | |
var predicate = NSPredicate(format: "SELF MATCHES %@", pattern) | |
// Using range | |
var range = email.range(of: pattern, options: .regularExpression) | |
// Using NSRegularExpression |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IMPORT | |
import SwiftKeychainWrapper | |
// SET | |
KeychainWrapper.standard.set("p@$$w0rd", forKey: "password") | |
// GET | |
guard let retrievedString = KeychainWrapper.standard.string(forKey: "password") else { return } // p@$$w0rd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Using Protocols | |
protocol EmptyInitilizable { | |
init() | |
} | |
protocol Combinable { | |
func combine(with other: Self) -> Self | |
} |
NewerOlder