emoji的表情存成uint32的形式,如0x1f60d、0x1f603等,可以通过系统方法转换为emoji的表情,emoji表情可以直接复制到其他地方打开。正常存储往往以字符串的形式保存。以下为Swift及oc版本的字符串转emoji表情的方式。

Swift

代码:

let code = "0x1f603"
//创建扫描器
let scanner = Scanner(string: code)
var result: UInt32 = 0
//利用扫描器扫出结果
scanner.scanHexInt32(&result)
//将结果转换成字符
let c = Character(UnicodeScalar(result)!)
//将字符转换成字符串
let emojiCode = String(c)

oc

代码:

NSString *emojiString = @"0x1f60d";

NSScanner *scanner = [NSScanner scannerWithString:emojiString];
uint32_t intCode = 0;
[scanner scanHexInt:&intCode];
NSString * result = [[NSString alloc] initWithBytes:&intCode length:4 encoding:NSUTF32LittleEndianStringEncoding];

Lynx
206 声望3 粉丝

步步