swift-playground/Variables.playground/Contents.swift

57 lines
841 B
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Foundation
// let
let myName = "Gary"
let yourName = "Foo"
// var
// structur
var names = [
myName,
yourName
]
names.append("Mike")
//
let foo = "Foo"
var foo2 = foo
foo2 = "Foo2"
foo
let moreName = [
"Gary",
"Mike",
"Sara"
]
// let -> var
var copy = moreName
copy.append("Foo")
moreName
// class let
let oldArray = NSMutableArray(
array: ["Mike", "Paul"]
)
oldArray.add("Baz")
var newArray = oldArray
newArray.add("Qux")
newArray
oldArray
//
let someNames = NSMutableArray(
array: ["Mike", "Paul"]
)
func changTheArray(_ array: NSArray) {
let copy_address = array as! NSMutableArray
copy_address.add("Bazz")
}
changTheArray(someNames)
someNames