Skip to content

Instantly share code, notes, and snippets.

View mehmetfarhan's full-sized avatar
🚀

Mohammad Farhan mehmetfarhan

🚀
View GitHub Profile
@mehmetfarhan
mehmetfarhan / Destructuring.swift
Created September 25, 2020 21:42
Destructuring
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) {
@mehmetfarhan
mehmetfarhan / CaptureList.swift
Created September 25, 2020 11:18
Capture List
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
@mehmetfarhan
mehmetfarhan / RemoteConfigManager.swift
Created August 11, 2020 18:09
Firebase Remote Config
import Foundation
import Firebase
struct RemoteConfigModel {
var url: String?
var forceUpdate: String?
var version: String?
}
final class RemoteConfigManager {
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
import AVFoundation
import UIKit
public class ScannerOverlayPreviewLayer: AVCaptureVideoPreviewLayer {
// MARK: - OverlayScannerPreviewLayer
public var cornerLength: CGFloat = 30
public var lineWidth: CGFloat = 6
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 }
}
}
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
}
@mehmetfarhan
mehmetfarhan / RegularExpressions.swift
Last active July 6, 2020 07:38
Regular Expressions
var email = "mehmetfarhan@gmail.com"
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
// IMPORT
import SwiftKeychainWrapper
// SET
KeychainWrapper.standard.set("p@$$w0rd", forKey: "password")
// GET
guard let retrievedString = KeychainWrapper.standard.string(forKey: "password") else { return } // p@$$w0rd
@mehmetfarhan
mehmetfarhan / Combinable & EmptyInitilizable.swift
Last active July 5, 2020 05:53
Combinable & EmptyInitilizable
// MARK: - Using Protocols
protocol EmptyInitilizable {
init()
}
protocol Combinable {
func combine(with other: Self) -> Self
}