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
//Protocal that copyable class should conform | |
protocol Copying { | |
init(original: Self) | |
} | |
//Concrete class extension | |
extension Copying { | |
func copy() -> Self { | |
return Self.init(original: 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
import UIKit | |
struct AppFontName { | |
static let regular = "CourierNewPSMT" | |
static let bold = "CourierNewPS-BoldMT" | |
static let italic = "CourierNewPS-ItalicMT" | |
} | |
extension UIFontDescriptor.AttributeName { | |
static let nsctFontUIUsage = UIFontDescriptor.AttributeName(rawValue: "NSCTFontUIUsageAttribute") |
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
// | |
// PaddedLabel.swift | |
// PaddedLabel | |
// | |
// Created by Mohammad Farhan on 4/27/19. | |
// Copyright © 2019 PaddedLabel. All rights reserved. | |
// | |
import UIKit |
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
private var badge = BadgeBarButtonItem() | |
var counterItem = 0 | |
@objc | |
func didTappedAddToCart(with imageView: UIImageView?) { | |
guard let imageView = imageView else { return } | |
let bounds = imageView.bounds | |
let size = imageView.frame.size |
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
final class XOREncryptionAndDecryption { | |
static func encript(_ text: String, cipher: String) -> String { | |
let text = [UInt8](text.utf8) | |
let cipher = [UInt8](cipher.utf8) | |
var encripted = [UInt8]() | |
for (index, item) in text.enumerated() { | |
encripted.append(item ^ cipher[index]) | |
} |
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 | |
} |
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
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
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 | |
} |
OlderNewer