Anton Afanasev
06/20/2022, 1:23 PMfun sendMessage(text: String, customAttributes: Map<String, String> = emptyMap())
translated to this:
func sendMessage(text: String, customAttributes: [String : String] = [:])
Am I seeing write?
kotlin 1.6.10kpgalligan
06/20/2022, 2:44 PMfunc sendMessage(text: String, customAttributes: [String : String] = [:])
That’s swift. The Kotlin compiler would be generating objc. Where do you see that? Default parameters aren’t available, unless something I’m not aware of happened.Anton Afanasev
06/20/2022, 3:01 PMJump To Definition
tool. Thats weird...fun sendMessage(text: String, customAttributes: Map<String, String> = emptyMap())
ios/swift
client.sendMessage(text: "Hello")
No warnings or errors.
But that only work with emptyMap. If I go and define some other default argument, lets say:
fun sendMessage(text: String, customAttributes: Map<String, String> = mapOf("a" to "b")
They default argument will be ignored and the value of customAttributes
in that case will be empty map as well.
Is it possible that K\N compiler always treat a map argument as an emptyMap, unless actual value is provided?Rick Clephas
06/20/2022, 4:08 PMAn argument whose Objective-C type is an NSDictionary defaults to nil if the NSDictionary is nullable and [:] if the NSDictionary is non-nullable, under the following conditions:
• the argument label contains the word “options” or “attributes”, or the two words “user info” one after another
• the argument label is empty and the method base name ends with the word “options” or “attributes”, or the two words “user info” one after anotherhttps://github.com/apple/swift/blob/main/docs/CToSwiftNameTranslation.md#default-argument-values
A final argument that is a nullable function or block pointer defaults to nil.
fun doSomething(block: (() -> Unit)?) = TODO()
can be called from Swift like:
doSomething() // default nil
doSomething { }
kpgalligan
06/20/2022, 4:34 PMAnton Afanasev
06/20/2022, 5:57 PMeaster egg