NAV Navbar
swift
  • Intro
  • Optional
  • Protocol
  • Generics
  • Intro

    Swift and iOS cheatsheet

    Main links: Apple Documentation Swift 4

    Optional

    Unwrap

    if way

    @IBOutlet var messageLabel: UILabel?
    
    if let messageLabel = messageLabel {
        messageLabel
    }
    

    Protocol

    Simple

    protocol MyProtocol {
    //Protocol code here
    }
    

    Extension

    extension MyProtocol {
    //Extension code here
    }
    

    Extension constraints

    only types that also conform to the MyAnotherProtocol protocol will receive the functionality defined in the extension

    extension MyProtocol where Self: MyAnotherProtocol {
    //Extension code here
    }
    

    Generics

    Constraints

    func fooFunction<T: MyClass, E: MyProtocol>(a: T, b: E) {
    }