Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
internal struct _NSSimpleObjCType: ExpressibleByStringLiteral {
fileprivate let staticString: StaticString
var rawValue: UnicodeScalar {
return staticString.unicodeScalar
}
var _objCType: UnsafePointer<Int8> {
return UnsafeRawPointer(staticString.utf8Start).assumingMemoryBound(to: Int8.self)
}
init(stringLiteral value: StaticString) {
staticString = value
}
}
extension _NSSimpleObjCType: Hashable {
var hashValue: Int {
return rawValue.hashValue
}
static func ==(lhs: _NSSimpleObjCType, rhs: _NSSimpleObjCType) -> Bool {
return lhs.rawValue == rhs.rawValue
}
}
extension _NSSimpleObjCType {
static let ID: _NSSimpleObjCType = "@"
static let Class: _NSSimpleObjCType = "#"
static let Sel: _NSSimpleObjCType = ":"
static let Char: _NSSimpleObjCType = "c"
static let UChar: _NSSimpleObjCType = "C"
static let Short: _NSSimpleObjCType = "s"
static let UShort: _NSSimpleObjCType = "S"
static let Int: _NSSimpleObjCType = "i"
static let UInt: _NSSimpleObjCType = "I"
static let Long: _NSSimpleObjCType = "l"
static let ULong: _NSSimpleObjCType = "L"
static let LongLong: _NSSimpleObjCType = "q"
static let ULongLong: _NSSimpleObjCType = "Q"
static let Float: _NSSimpleObjCType = "f"
static let Double: _NSSimpleObjCType = "d"
static let Bitfield: _NSSimpleObjCType = "b"
static let Bool: _NSSimpleObjCType = "B"
static let Void: _NSSimpleObjCType = "v"
static let Undef: _NSSimpleObjCType = "?"
static let Ptr: _NSSimpleObjCType = "^"
static let CharPtr: _NSSimpleObjCType = "*"
static let Atom: _NSSimpleObjCType = "%"
static let ArrayBegin: _NSSimpleObjCType = "["
static let ArrayEnd: _NSSimpleObjCType = "]"
static let UnionBegin: _NSSimpleObjCType = "("
static let UnionEnd: _NSSimpleObjCType = ")"
static let StructBegin: _NSSimpleObjCType = "{"
static let StructEnd: _NSSimpleObjCType = "}"
static let Vector: _NSSimpleObjCType = "!"
static let Const: _NSSimpleObjCType = "r"
private static let allTypes = [
_NSSimpleObjCType.ID, Class, Sel, Char, UChar, Short, UShort, Int, UInt, Long, ULong,
LongLong, ULongLong, Float, Double, Bitfield, Bool, Void, Undef, Ptr, CharPtr, Atom,
ArrayBegin, ArrayEnd, UnionBegin, UnionEnd, StructBegin, StructEnd, Vector, Const,
]
init?(rawValue: UnicodeScalar) {
if let candidate = _NSSimpleObjCType.allTypes.first(where: { $0.rawValue == rawValue }) {
self = candidate
} else {
return nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment