View File Reference URL in Swift.swift
This file contains 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
if let refURL = (a as NSURL).perform(#selector(NSURL.fileReferenceURL))?.takeUnretainedValue() as? NSURL { | |
print(refURL) | |
} |
View Type Casts.swift
This file contains 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 typecast<T,U>(_ a:T) -> U { | |
var _a = a | |
return withUnsafePointer(to: &_a) { (ptr:UnsafePointer<T>) -> U in | |
return UnsafeRawPointer(ptr).load(as: U.self) | |
} | |
} | |
func typecast_inplace<T,U>(_ a:inout T) -> U { | |
return withUnsafePointer(to: &a) { (ptr:UnsafePointer<T>) -> U in | |
return UnsafeRawPointer(ptr).load(as: U.self) |
View NSClassFromSwift.swift
This file contains 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
class YourClass { | |
required init() { | |
} | |
func saySomething() { | |
print("Hi!") | |
} | |
} | |
if let classType = NSClassFromString("APPNAMEORMODULE.YourClass") as? YourClass.Type { |
View gist:9aae80d96568be8d5996790ac0214810
This file contains 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
protocol HasInit { | |
init() | |
func sayHi() | |
} | |
extension HasInit { | |
func sayHi() { print("Hi from an instance of \(type(of: self))") } | |
} |