Skip to content

Instantly share code, notes, and snippets.

View luannguyenkhoa's full-sized avatar

Luan Nguyen luannguyenkhoa

View GitHub Profile
@luannguyenkhoa
luannguyenkhoa / UrlDetection.swift
Last active May 29, 2017 10:18
Get all properly formatted urls from a text by combining NSDataDetector vs NSRegularExpression
struct Regex {
static let urlRegex: NSRegularExpression? = {
do {
return try NSRegularExpression(pattern: "(http(s)?:\\/\\/)?(www\\.)?[-a-zA-Z0-9\\@:%_\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9\\@:%_\\+.~#?&//=]*)", options: .caseInsensitive)
} catch {
return nil
}
}()
@luannguyenkhoa
luannguyenkhoa / UDKey.swift
Last active November 1, 2022 01:56
A way to manage UserDefault in Swift by utilizing the combination of Enum and Protocol, combined with CryptoSwift to encrypt the sensitive info before storing.
import CryptoSwift
/*
Where controls all actions related to save and retrieve value from User Default
All strings value will be encrypted/decrypted before saving/retrieving from UD
Other types will be save/retrieve directly
*/
public protocol UD {