Created
July 21, 2014 18:16
-
-
Save iamatypeofwalrus/6a1654e09f31db5f002a to your computer and use it in GitHub Desktop.
A convoluted way to add an Integer to a Character and get another Character in Swift
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
// Per the BNR iOS programming guide's chapter on creating BNRItem | |
import Cocoa | |
import Foundation | |
extension Character { | |
func unicodeIntValue() -> UInt32 | |
{ | |
let str = String(self) | |
return str.unicodeScalars[str.unicodeScalars.startIndex].value | |
} | |
func addIntToCharacter(value: UInt32) -> Character | |
{ | |
let old_int = self.unicodeIntValue() | |
return Character(UnicodeScalar(old_int + value)) | |
} | |
} | |
let thing = Character("A") | |
thing.addIntToCharacter(UInt32(10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment