Ok so in the first tutorial we covered let, which is the keyword for defining constants.
let thisBeAConstant = 3.141
Now we are going to cover variables, which use the var keyword like so:
var thisVariable = time
Notice 2 things about Swift:
1) We don’t use ; at the end of a line. That’s just weird 🙂
2) We don’t have to specify the type. The type is inferred by whatever value you pass in, so:
var someString = “this is a string”
var someInteger = 5
So Swift is kinda smart. Now let’s meet some old friends “Hao jiu bu juan”
ARRAYS
var energies = [“solar”, “wind”, “fossil”, “this is a mixed array”, 39]
var energies:String[] = [“solar”, “wind”, “this is a string array”]
And of course we can perform some basic operations such as:
READ
var item1 = energies[0] // “solar”
INSERT
energies.insert(“hydro”, atIndex: 2)
MODIFY
energies[3] = “geothermal”
APPEND
energies.append(“nuclear”)
or
energies += “nuclear”
COMBINE
energies += [“biomass”, “hamster”]
COUNT
var lengthofArray = energies.count
LOGIC
var arrayIsEmpty = energies.isEmpty
REMOVE
energies.removeAtIndex(3)energies.removeLast()energies.removeAll(keepCapacity: true)
var energies = [
“Solar”: “Thermal”,“Photovoltaic” : “Grid”,“Nuclear” : “Dangerous”]
let cheapestSolarEnergy = energies[“Solar”]
var energiesCount = energies.count
energies[“Solar”] = “PV”
energies[“Nuclear”] = nil;
energies[“Geo”] = “Thermal”
var typesOfEnergy =
[platforms[“Solar”]: [“Thermal”, “PV”, “GridTied”],platforms[“Wind”]: [“Autonomous”, “GridTied”],platforms[“Nuclear”] : [“Fusion”, “Fission”,“Meltdown”]]
var type1 = typesOfEnergy[“Solar”][0]
I think this is among the most significant information for me.
And i am glad reading your article. But wanna remark on few general things, The site style is
ideal, the articles is really great : D. Good job, cheers