Skip to content

Instantly share code, notes, and snippets.

View ArchieR7's full-sized avatar
👨‍💻

Archie Chang ArchieR7

👨‍💻
View GitHub Profile
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
/* Create a Foundation object from JSON data. Set the NSJSONReadingAllowFragments option if the parser should allow top-level objects that are not an NSArray or NSDictionary. Setting the NSJSONReadingMutableContainers option will make the parser generate mutable NSArrays and NSDictionaries. Setting the NSJSONReadingMutableLeaves option will make the parser generate mutable NSString objects. If an error occurs during the parse, then the error parameter will be set and the result will be nil.
The data must be in one of the 5 supported encodings listed in the JSON specification: UTF-8, UTF-16LE, UTF-16BE, UTF-32LE, UTF-32BE. The data may or may not have a BOM. The most efficient encoding to use for parsing is UTF-8, so if you have a choice in encoding the data passed to this method, use UTF-8.
*/
open class func jsonObject(with data: Data, options opt: JSONSerialization.ReadingOptions = []) throws -> Any
/*
{
"status": true,
"user": {
"ID": "1234567890",
"name": "Archie",
"email": "example@example.com"
}
*/
/*
{
"name": "Archie",
"email": "example@example.com",
"status: "Active",
"updated_time": "2017-09-20T00:00:00Z"
}
*/
enum UserStatus: String, Codable {
if let url = Bundle.main.url(forResource: ImageName, withExtension: ".png"),
let data = try? Data(contentsOf: url,
options: Data.ReadingOptions.uncached) {
let image = UIImage(data: data)
imageView.image = image
}
private func scaleMapImage(_ image: UIImage?, size: CGSize) -> UIImage? {
        guard let image = image else {
            return nil
        }
        UIGraphicsBeginImageContext(CGSize(width: size.width, height: size.height))
public init(type: String, localizedTitle: String, localizedSubtitle: String?, icon: UIApplicationShortcutIcon?, userInfo: [AnyHashable : Any]? = nil)
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void)
@ArchieR7
ArchieR7 / html.swift
Created April 11, 2018 16:16
convert to swift NSMutableAttributedString
var htmlString = NSMutableAttributedString()
do {
if let data = self.data(using: String.Encoding.unicode, allowLossyConversion: true) {
htmlString = try NSMutableAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)
}
} catch {
print(error)
}
@ArchieR7
ArchieR7 / UUID+v5.swift
Created September 12, 2018 13:06
UUID initialize with version 3, 5 and namespace
extension UUID {
enum UUIDVersion: Int {
case v3 = 3
case v5 = 5
}
enum UUIDv5NameSpace: String {
case dns = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
case url = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
case oid = "6ba7b812-9dad-11d1-80b4-00c04fd430c8"