Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

AltConf 2015: Swift Thinking

1,016 views

Published on

Swift Thinking - talk originally presented at Alt Conf 2015 http://altconf.com/

Published in: Technology
  • Be the first to comment

AltConf 2015: Swift Thinking

  1. 1. Swift Thinking @NatashaTheRobot
  2. 2. @NatashaTheRobot • Swift Newsletter - swiftnews.curated.co • NatashaTheRobot.com
  3. 3. Learning…
  4. 4. Work with Others
  5. 5. Teach
  6. 6. Put Your Stuff Out There
  7. 7. Expose Yourself to Advanced Topics
  8. 8. Celebrate Breakthroughs
  9. 9. @ashsmash
  10. 10. Learning… • Value Types • Optionals?! • Testing
  11. 11. Value Types
  12. 12. • structs • enums • (tuples)
  13. 13. class Person { let name: String var age: Int init(name: String, age: Int) { self.name = name self.age = age } }
  14. 14. let taylorSwift = Person(name: "Taylor Swift", age: 25) func timeTravelToBirthdayForPerson(var person: Person) { person.age += 1 () } timeTravelToBirthdayForPerson(taylorSwift) taylorSwift.age // 26
  15. 15. let taylorSwift = Person(name: "Taylor Swift", age: 25) func timeTravelToBirthdayForPerson(person: Person) { person.age += 1 🎉🎂🎁🎈💥() } timeTravelToBirthdayForPerson(taylorSwift) taylorSwift.age // 26
  16. 16. let taylorSwift = Person(name: "Taylor Swift", age: 25) func timeTravelToBirthdayForPerson(var person: Person) { person.age += 1 🎉🎂🎁🎈💥() } timeTravelToBirthdayForPerson(taylorSwift) taylorSwift.age // 26
  17. 17. struct Person { let name: String var age: Int // NO INIT NEEDED }
  18. 18. let taylorSwift = Person(name: "Taylor Swift", age: 25) func timeTravelToBirthdayForPerson(var person: Person) { person.age += 1 () } timeTravelToBirthdayForPerson(taylorSwift) taylorSwift.age // 25
  19. 19. let taylorSwift = Person(name: "Taylor Swift", age: 25) func timeTravelToBirthdayForPerson(var person: Person) { person.age += 1 🎉🎂🎁🎈💥() } timeTravelToBirthdayForPerson(taylorSwift) taylorSwift.age // 25
  20. 20. let taylorSwift = Person(name: "Taylor Swift", age: 25) func timeTravelToBirthdayForPerson(var person: Person) { person.age += 1 🎉🎂🎁🎈💥() } timeTravelToBirthdayForPerson(taylorSwift) taylorSwift.age // 25
  21. 21. let taylorSwift = Person(name: "Taylor Swift", age: 25) func timeTravelToBirthdayForPerson(var person: Person) { person.age += 1 🎉🎂🎁🎈💥() } timeTravelToBirthdayForPerson(taylorSwift) taylorSwift.age // 25
  22. 22. @andy_matuschak • Functional Swift Conference: Functioning as a Functionalist • Realm: Controlling Complexity in Swift
  23. 23. –Functional Swift Book “Almost all types in Swift are value types, including arrays, dictionaries, numbers, booleans, tuples, and enums. Classes are the exception rather than the rule.”
  24. 24. $ grep -e "^struct " swift.md | wc -l 87 $ grep -e "^enum " swift.md | wc -l 8 $ grep -e "^class " swift.md | wc -l 4
  25. 25. Optionals?!
  26. 26. –Sunset Lake Software “~40% of bugs shipped to customers in the last three years would have been caught immediately by using Swift”
  27. 27. Objc.io Issue 13
  28. 28. struct Person { let name: String var age: Int }
  29. 29. struct PersonViewModel { var name: String? var age: String? }
  30. 30. class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var nameTextField: UITextField! @IBOutlet weak var ageTextField: UITextField! var personViewModel = PersonViewModel() override func viewDidLoad() { super.viewDidLoad() } func textFieldDidEndEditing(textField: UITextField) { personViewModel.name = nameTextField.text personViewModel.age = ageTextField.text } }
  31. 31. struct PersonViewModel { var name: String? var age: String? enum InputError: ErrorType { case InputMissing case AgeIncorrect } func createPerson() throws -> Person { guard let age = age, let name = name else { throw InputError.InputMissing } guard let ageFormatted = Int(age) else { throw InputError.AgeIncorrect } return Person(name: name, age: ageFormatted) } }
  32. 32. class ViewController: UIViewController, UITextFieldDelegate { var personViewModel = PersonViewModel() // ... truncated ... // @IBAction func onSubmitButtonTap(sender: AnyObject) { view.endEditing(true) do { let person = try personViewModel.createPerson() print("Success! Person created. (person)") } catch PersonViewModel.InputError.InputMissing { print("Input missing!") } catch PersonViewModel.InputError.AgeIncorrect { print("Age Incorrect!") } catch { print("Something went wrong, please try again!") } } }
  33. 33. Failable initializers, revisited @jesse_squires
  34. 34. Testing
  35. 35. • Performance Tests • Asynchronous Tests • Xcode CI Improvements • UI Tests • Code Coverage
  36. 36. Still Learning… • Value Types • Optionals?! • Testing
  37. 37. To Learn… • do • guard • defer • error handling • protocol extensions • print • pattern matching • early exits • UI Testing • WatchOS • UIStackView • Security • Complications • Continuous Integration • App Thinning • Crash Logs • Objective-C Generics

×