I read the The Swift Programming Language
iBook.
In the keywords section they listed new
. But in the section Summary of the Grammar
I didn't found it.
For what is new
used in Swift?
The new keyword is used in javascript to create a object from a constructor function. The new keyword has to be placed before the constructor function call and will do the following things: Creates a new object. Sets the prototype of this object to the constructor function's prototype property.
The new operator creates a new instance of a type. You can also use the new keyword as a member declaration modifier or a generic type constraint.
The new keyword constructs and returns an object (instance) of a constructor function. The new keyword performs following four tasks: It creates new empty object e.g. obj = { }; It sets new empty object's invisible 'prototype' property to be the constructor function's visible and accessible 'prototype' property.
It seems that new
can be used to create an array:
let x = new Double[2]
x[0] = 3.1
x[1] = 4.2
println(x)
// Output: [3.1, 4.2]
But this is only of theoretical interest. It is not documented and should therefore not be used.
It seems to have been removed.
I tried let x = new Double[2]
but in Xcode 7 it now throws an error
Playground execution failed: OSX.playground:1:9: error: use of unresolved identifier 'new' let a = new [Double]
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