Hi, can someone please guide me if i need to use `...
# kotlin-native
s
Hi, can someone please guide me if i need to use
autoreleasepool { }
in this code?
Copy code
private fun getEncoding(name: String): NSStringEncoding {
        val encoding = name.uppercase().useCFStringRef { CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding(it)) }
        if (encoding.toUInt() != kCFStringEncodingInvalidId) {
            return encoding
        } else {
            throw IllegalArgumentException("Charset $name is not supported by apple.")
        }

inline fun <T> String.useCFStringRef(block: (CFStringRef) -> T): T {
    val ref = CFBridgingRetain(this as NSString) as CFStringRef
    return block(ref).also { CFRelease(ref) }
}