Giter Club home page Giter Club logo

advanced-swift-notes's Introduction

Advanced Swift Notes

A collection of notes on the excellent book Advanced Swift by Chris Eidhof and Airspeed Velocity.

Swift Style Guide

###Array

Array is a value types but the items it contains may not be. Assigning an Array to a new constant or variable creates a shallow copy unless the items held are also value types in which case it is a deep copy.

SequenceType's map, filter and reduce remove the boiler plate code of a simliar operation allowing the unique transformation code to surface.

It is possible to use sort and contains in interesting ways. ie.

people.contains { $0.age < 18 }

Consider writing extensions for SequenceType when you find yourself writing collection lookup code.

Handy functions

extension SequenceType {
    func findElement (match: Generator.Element->Bool) -> Generator.Element? {
        for element in self where match(element) {
            return element
        }
        return nil
    }
}

Excerpt From: Chris Eidhof. “Advanced Swift.” iBooks.

###Dictionary

Handy functions

extension Dictionary {
    mutating func merge<S: SequenceType
        where S.Generator.Element == (Key,Value)>(other: S) {
        for (k, v) in other {
            self[k] = v
        }
    }
}

###SequenceType (generally)

extension SequenceType where Generator.Element: Hashable {
    func unique() -> [Generator.Element] {
        var seen: Set<Generator.Element> = []
        return filter {
            if seen.contains($0) {
                return false
            } else {
                seen.insert($0)
                return true
            }
        }
    }
}

advanced-swift-notes's People

Contributors

steam avatar

Watchers

 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.