Skip to content

Instantly share code, notes, and snippets.

View mehmetfarhan's full-sized avatar
🚀

Mohammad Farhan mehmetfarhan

🚀
View GitHub Profile
@mehmetfarhan
mehmetfarhan / ArrayDeepCopy.swift
Created September 20, 2017 05:50 — forked from sohayb/ArrayDeepCopy.swift
Array deep copy in Swift
//Protocal that copyable class should conform
protocol Copying {
init(original: Self)
}
//Concrete class extension
extension Copying {
func copy() -> Self {
return Self.init(original: self)
}
@mehmetfarhan
mehmetfarhan / UIFont
Created December 15, 2018 11:19
Override the system font "swift 4" "iOS"
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")
@mehmetfarhan
mehmetfarhan / PaddedLabel.swift
Last active April 26, 2019 21:37
PaddedLabel
//
// PaddedLabel.swift
// PaddedLabel
//
// Created by Mohammad Farhan on 4/27/19.
// Copyright © 2019 PaddedLabel. All rights reserved.
//
import UIKit
//
// SocialNetwork.swift
// SocialNetwork
//
// Created by Mohammad Farhan on 4/27/19.
// Copyright © 2019 SocialNetwork. All rights reserved.
//
import UIKit
@mehmetfarhan
mehmetfarhan / FlayCart.swift
Created May 9, 2019 13:14
Flay Shopping Cart
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
@mehmetfarhan
mehmetfarhan / XOREncryptionAndDecryption.swift
Last active June 28, 2020 09:47
XOR encryption and decryption
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])
}
@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
}
// 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 / 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
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
}