iOS Swift – Playground


I started learning Swift (via https://www.udemy.com/complete-ios-developer-course) a few months ago. I was planning to create an application that will give me alerts for specific stock data price changes. Although this app hasn’t materialize yet, I find from developing that app, that learning Swift seems to be very straight forward and easy. The language itself is not that complicated to learn – as long as you are familiar with the C-style syntax. The XCode application is remarkable in its development tools. The IDE has a wide range of features that can help an app developer initiate and finally upload their apps on the app store.

Of course, for the likes of me, I haven’t really uploaded an app yet since I’m still learning the language, but I’m really impresses with the wide variety of channels that can be used to learn the language. One I wanted to be specific about is the Playground.

The playground is just a project within xcode that a student can use to code Swift. It can be use as a running ground to write code and see the results instantly.

//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"
var name:String = "String"

var number:Int = 1;
var numberD:Double = 10/42;
var numberF:Float = 10/21;
var newString:String = "111";

print("Hello world!!!");

print(newString);

//var numberX = "90";
var numberX:Double = 0.0;
print("\(numberX)");

var array = ["as0","as1"];
array.removeAtIndex(0);

var dict = ["name":"Alvin","Description":"Description of Alvin"];

dict["name"]
var nameStr:String = "name";

var textSample:String = "My name is \(dict[nameStr]!)";

var dict1 = [["name":"name1","desc":"desc1"],["name":"name2","desc":"desc2"]];

dict1[0]["name"];


if dict1[0]["name"] == "name1" {
    print("Hello World!");
}


var random = arc4random_uniform(10)
print("The random number is \(random) ");


for var i = 1;i<10;i++ {
    print("This is \(i)");
}

var arr = ["aa","aa1","aa2"]

for x in arr {
    print(x);
}

print("hello");

let arr1 = ["1","2","3"]
for x in arr1 {
    print(x);

}

var g = 0;
while g < 5 { print(g); g++; } var str1:String = "1"; func polymorphMe(inout name1:String, name2:String) { name1 += "Hello"; } polymorphMe(&str1,name2: ""); print(str1); func getEverything(name1 name2:String, description1 desc:String) -> (Int,Int) {
    
    return (1,1);
    
}

That’s a direct copy and paste of my playground code. It has all the basics syntax and powerful features of Swift. I just hope I can finish an app with it before 2016. 🙂

I would certainly recommend anyone who’s learning Swift to use this tool and follow Rob Percievals Udemy course! (I highly recommend it!)

Happy coding!