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
| @interface NSFileHandle (fhreadline) | |
| -(NSString*)readLine; | |
| @end | |
| @implementation NSFileHandle (fhreadline) | |
| -(NSString*)readLine | |
| { | |
| unsigned long long pos = [self offsetInFile]; | |
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 Foundation | |
| import CommonCrypto | |
| public typealias DigestHashFunc = @convention(c)(UnsafePointer<Void>, CC_LONG, UnsafeMutablePointer<UInt8>) -> UnsafeMutablePointer<UInt8> | |
| public extension NSData { | |
| var md4: NSData { return digetstHash(CC_MD4, CC_MD4_DIGEST_LENGTH) } | |
| var md5: NSData { return digetstHash(CC_MD5, CC_MD5_DIGEST_LENGTH) } | |
| var sha1: NSData { return digetstHash(CC_SHA1, CC_SHA1_DIGEST_LENGTH) } |
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 struct Path { | |
| public static var documents: String { return NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] } | |
| public static var caches: String { return NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0] } | |
| public static var library: String { return NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0] } | |
| public static var support: String { return NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true)[0] } | |
| public static var temp: String { return NSTemporaryDirectory() } | |
| public static var resource: String { return Bundle.main.resourcePath ?? "" } | |
| @discardableResult public static func remove(_ path: String) -> Bool { | |
| do { |
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 struct Dispatch { | |
| public static func main(block: @escaping ()->()) { | |
| return DispatchQueue.main.async(execute: block) | |
| } | |
| public static func background(block: @escaping ()->()) { | |
| return DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async(execute: block) | |
| } |
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 extension NSObject { | |
| func removeNotifications() { | |
| NSObject.cancelPreviousPerformRequests(withTarget: self) | |
| NotificationCenter.default.removeObserver(self) | |
| } | |
| func addNotification(_ aSelector: Selector, key: String) { | |
| NotificationCenter.default.addObserver(self, selector: aSelector, name: NSNotification.Name(rawValue: key), object: nil) | |
| } |
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 extension Data { | |
| var JSONObject: NSObject { | |
| return (try? JSONSerialization.jsonObject(with: self, options: .allowFragments)) as? NSObject ?? NSObject() | |
| } | |
| var XMLObject: Any { | |
| let x = XMLParser() | |
| return x.parse(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
| public extension Date { | |
| static func dataformatter() -> DateFormatter { | |
| let f = DateFormatter() | |
| f.locale = Locale(identifier: "en_US_POSIX") | |
| f.timeZone = TimeZone.autoupdatingCurrent | |
| f.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" // ISO8601 | |
| return f | |
| } |
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 extension Bundle { | |
| func infoStringForKey(_ key: String) -> String { | |
| return object(forInfoDictionaryKey: key) as? String ?? "" | |
| } | |
| var version: String { return infoStringForKey("CFBundleShortVersionString") } | |
| var build: String { return infoStringForKey("CFBundleVersion") } | |
| var displayName: String { return infoStringForKey("CFBundleDisplayName") } | |
| var identifier: String { return infoStringForKey("CFBundleIdentifier") } | |
| } |
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
| extension NSDictionary { | |
| func lastof(path: String) -> Any? { | |
| var r: NSDictionary? = self | |
| let ar = path.components(separatedBy: "/") | |
| for a in ar.dropLast() { | |
| if a.isEmpty { continue } | |
| r = r?[a] as? NSDictionary | |
| if r == nil { return nil } | |
| } |
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
| func refrectedString(_ iobj: Any?, indent: String = "") -> String { | |
| guard let obj = iobj else { return "null" } | |
| let m = Mirror(reflecting: obj) | |
| if m.displayStyle == nil { | |
| if let s = obj as? String { return "\"\(s)\"" } | |
| return "\(obj)" | |
| } |
OlderNewer