Git Product home page Git Product logo

ios-parttime-swift-playgrounds-w1d1's Introduction

Swift Cheat Sheet

Variables

var myNumber = 5  
myNumber = 6 // setting the value of myNumber to now be 6 instead of 5
var myDouble:Double = 5 // explicitly defining  myDouble to be a Double type  

Constants

let myNumber = 5
myNumber = 4 // error, not allowed to mutate myNumber

Types

Int: A whole number ex) 5  
Double: A number with more precision ex) 5.55  
String: A collection of characters inside quotation marks ex) "Hello"
Bool: true or false

Control Flow

var firstNumber = 1
var secondNumber = 1

if firstNumber == secondNumber {

	// write code in here to run if firstNumber is equal to secondNumber

} else {

	// write code in here to run if firstNumber is NOT equal to secondNumber
	
}
var finalNumber = 5

for i in 1...finalNumber {
	print(i)
}

// prints the numbers 1 to 5

Functions and Methods

func greet() {
	print("Hello!")
}

func greet(name:String) {
	print("Hello \(name)")
}

func greet(name:String) -> String{
	return "Hello \(name)"
}

Arrays

var scores = [74, 94, 88]
scores[0] // returns 74
scores[3] // error, nothing in index 3
scores[3] = 99 // sets the value at index 3 to be 99

var scores = [Int]() // initializes a blank array where every element in this array is an Int

Dictionaries

var scores:[String:Int] = ["Dan": 74, "Paul": 94]
scores["Tom"] = 88 //scores now has a value for the key "Tom"

var scores = [String:Int]() // initializes a blank dictionary where the key is of type String, and the value is of type Int

Classes

class ClassName : ParentClass {

	let aVariable = 0
	
	func aFunction() -> String {
		returns "A String"
	}
	

}

ios-parttime-swift-playgrounds-w1d1's People

Contributors

dmathewwws avatar marc-maguire avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.