First of all, you need to know that plist editor of Xcode can contain emojis directly:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>emojis</key> <array> <string>😀</string> <string>😂</string> <string>😁</string><!-- or you can use numeric reference of XML, in XML editor --> </array> </dict> </plist>
But, if you already have some escaped version of plist file, you may need to convert it. Using NSRegularExpression, you can write something like this:
class EscapedUnicodeConverter: NSRegularExpression { override func replacementString(for result: NSTextCheckingResult, in string: String, offset: Int, template templ: String) -> String { if result.numberOfRanges == 2, case let nsString = string as NSString, case let matchedString = nsString.substring(with: result.rangeAt(1)), let unicodeScalarValue = UInt32(matchedString, radix: 16), let unicodeScalar = UnicodeScalar(unicodeScalarValue) { return String(unicodeScalar) } else { return super.replacementString(for: result, in: string, offset: offset, template: templ) } } } //Using pattern for Swift let unicodeConverterForSwift = try! EscapedUnicodeConverter(pattern: "\\\\u\\{([0-9A-Fa-f]+)\\}") let origStr = "\\u{1f600}" let result = unicodeConverterForSwift.stringByReplacingMatches(in: origStr, range: NSRange(0..<origStr.utf16.count), withTemplate: "???") print(result) //->😀