Last active
April 10, 2018 14:05
-
-
Save pjwelcome/c674aca8e1997853a862fd3f03e8272e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
//ARC (Weak and Strong reference) | |
class User : NSObject { | |
let name : String = "" | |
weak var surname : NSString? = "" | |
} | |
// var and let | |
let name : String = "Peter" | |
var surname : String = "John" | |
surname = "welcome" | |
// Access Control (public , internal, fileprivate, private) | |
class UserName { | |
fileprivate let hello : String = "" | |
} | |
protocol Coloring { | |
} | |
extension UserName : Coloring { | |
} | |
// type inference | |
let age = 26 | |
//classes and structs | |
class Box { | |
var type : String | |
init(_ type : String = "hello" ,_ something:String = "sadsa") { | |
self.type = type | |
} | |
} | |
Box() | |
struct Team { | |
var name : String? | |
init? (){ | |
if name == nil { | |
return nil | |
} | |
name = "" | |
} | |
} | |
// init and deinit , covenience init, failable init | |
// type casting (is , as ) | |
struct Red : Coloring { | |
let redType : String = "wqe" | |
} | |
struct Green : Coloring { | |
let greenType : String = "" | |
} | |
let list : [Coloring] = [Green(), Red()] | |
list.forEach { | |
if $0 is Red { | |
($0 as? Red)?.redType | |
} | |
} | |
//mutating | |
class MutatingStruct { | |
var counter = 0 | |
mutating func increments() { | |
self.counter = counter + 1 | |
} | |
} | |
//override and preventing override(final) | |
final class asdas { | |
lazy var naming : MutatingStruct = { | |
return MutatingStruct() | |
}() | |
} | |
asdas().naming | |
//lazy | |
// read only properties | |
@objc | |
class Organization : NSObject { | |
var name : String = "" { | |
willSet { | |
} | |
didSet { | |
} | |
} | |
public private(set) var team : String = "" | |
} | |
// property observers (willSet , didSet) | |
// String interpolation \() | |
let hello = "Hello" | |
let world = "World" | |
let helloWorld = "\(hello) \(world)" | |
// Booleans | |
let bo = true | |
// typealis | |
typealias DVT = Box | |
class H { | |
} | |
// tuples | |
func greeting() -> (hello : String,name : String, surname : String) { | |
return ("Hello","Peter", "welcome") | |
} | |
greeting().surname | |
// optionals | |
let nameSuranme : String? = nil | |
// if let statements | |
//if let name1 = nameSuranme { | |
//} | |
// guard statement | |
//guard let name2 = nameSuranme else { | |
// return | |
//} | |
// Error handling with do try catch and throws | |
enum DomainErrors : String { | |
case Error404 = "404" | |
} | |
//do { | |
// try | |
//} catch let error { | |
// | |
//} | |
// Ternary Operator | |
// Range Operator (1...5 or 1..<5) | |
for i in 1...5 { | |
i | |
} | |
// Collection Types (Arrays, Set, Dictionary) | |
let dict : [String:String] = ["Key":"Value"] | |
// Switch statement | |
// functions | |
func hello (name: @escaping (String) -> String) -> ((String) -> String){ | |
return name | |
} | |
hello { | |
$0 | |
} | |
// functions with multiple return types (tuples) | |
// argument Labels | |
// pattern match argument labels | |
// default parameters | |
// variadic Parameters (“func arithmeticMean(_ numbers: Double...) -> Double” | |
func arithmeticMean(_ numbers: Double...) -> Double { | |
func hello () -> Double { | |
return 1 | |
} | |
return hello() | |
} | |
let function : (_ numbers: Double...) -> Double = arithmeticMean(_:) | |
arithmeticMean(12 , 123, 123123) | |
//inout parameters | |
// functions as a type | |
// Nested Functions | |
// Closures | |
// enums | |
// protocols | |
// extensions | |
// protocol extensions | |
// Generics (Associated Types) | |
// Protocol Composition type ( protocol & protocol ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment