It's kind of funny that Swift loses the object wrapper notation from ObjC (NSNumber *number = @(aPrimitive)
). While NSNumber conforms to FloatLiteralConvertible
, IntegerLiteralConvertible
, and BooleanLiteralConvertible
, if you have an existing value in a primitive format, you have to use the full initializer name for that given type. It feels very weird in Swift, which is all about type inference, that it can't infer what type of NSNumber to use. Even worse, because C and Swift use different names for their types, it can be confusing knowing which initializer to user.
In Swift 2, we can mark methods as being Swift only, which allows us to create our own initializers using Swift's infered initializer syntax. Previously the compiler would complain that the methods were identical to their existing ObjC counterparts.