Last active
August 29, 2015 14:02
-
-
Save cxa/bb8708a8214fe6d02365 to your computer and use it in GitHub Desktop.
Swift example: Interacting with C APIs
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
// BridgeHeader.h | |
#import <unicode/uchar.h> | |
// UnicodeBlock.swift | |
import Foundation | |
class UnicodeBlock { | |
class var blocks: UnicodeBlock[] { | |
var blocks = UnicodeBlock[]() | |
let start = Int32(UBLOCK_NO_BLOCK.value) | |
let count = Int32(UBLOCK_COUNT.value) | |
for i in start..count { | |
let n = u_getPropertyValueName(UCHAR_BLOCK, i, U_LONG_PROPERTY_NAME) | |
let name = NSString(CString: n, encoding: NSUTF8StringEncoding).stringByReplacingOccurrencesOfString("_", withString: " ") | |
let block = UnicodeBlock(name: name, code: Int(i)); | |
blocks.append(block); | |
} | |
return blocks; | |
} | |
let name: String | |
let code: Int | |
init(name: String, code: Int){ | |
self.name = name | |
self.code = code | |
} | |
var description: String { | |
return String("Unicode block name “\(name)” at UBlockCode: \(code)"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment