Skip to content

Instantly share code, notes, and snippets.

@ibhavin
Last active September 21, 2016 12:06
Show Gist options
  • Save ibhavin/daab1b3e9761b7f05491f1efa4cd4b18 to your computer and use it in GitHub Desktop.
Save ibhavin/daab1b3e9761b7f05491f1efa4cd4b18 to your computer and use it in GitHub Desktop.
Array - Dictionary - Functions (Swift playground)
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, welcome to playground tutorial"
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var str1 : String = "Bhavin "
var str2 : String = "Ramani"
var combine_str : String = str1 + str2
if str1==str2 { print("Both are same string") }
else { print("not same string") }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var itemList = ["Apple","Nokia","Samsung","Gionee"]
itemList.append("Dell")
itemList += ["Oppo"]
itemList [4] = "Lava"
itemList[2...4] = ["Banannas", "Mango"]
itemList.insert("Grapes", atIndex: 5)
itemList.removeLast()
print(itemList)
itemList.count
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var dictionary = ["Apple":"iPhone","Nokia":"Asha","Samsung":"Galaxy"]
dictionary["Apple"]
dictionary["Gionee"]="P4"
for (key, value) in dictionary
{
key
value
}
print(dictionary)
dictionary.count
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
func hello(personName : String) -> String {
return "Hello, \(personName)"
}
hello("Bhavin Ramani")
func myInfo(age : Int, occupation : String) -> String {
return "My age is \(age) and I am a \(occupation)"
}
myInfo(55, occupation: "soldier")
func addNumbers(a : Int, b : Int) -> Int {
return a + b
}
addNumbers(12, b: 34)
func calculate(a : Int, b : Int, _multiply : Int = 1) -> Int {
return (a + b)*_multiply
}
calculate(2, b: 2)
calculate(4, b: 4,_multiply: 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment