Skip to content

Instantly share code, notes, and snippets.

@cxa
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cxa/bb8708a8214fe6d02365 to your computer and use it in GitHub Desktop.
Save cxa/bb8708a8214fe6d02365 to your computer and use it in GitHub Desktop.
Swift example: Interacting with C APIs
// 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