I recently noticed that some codes do init of instances like ClassName.self() for example:
let realm = try! Realm.self()
From the output and the usage thereafter, it is just like as though without it - Realm()
Is there any specific reason or usage for doing an init with .self?
This is somewhat speculation, but I believe the places that do use Type.self() in the context of Realm follows a misperceived convention that has followed (some irrelevantly) the effects of Swift team resolving the bug
.self can be omitted if a function has only one parameterThe following commit by the Realm team was in preparation for the anticipated resolution of the bug above:
Type.self' notation when passing types to Realm Swift APIs It's possible that the changes in the commit above (Type updated to Type.self, in proper context) has inspired code bases that make use of Realm to also make use of Type.self in initializer context, i.e., Type.self(). This is, however, a redundant use of the .self suffix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With