a guest Jun 15th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Introducing Swift UI
  2. ## Building your First App
  4. *To use previews you need macOS Catalina*
  6. * Canvas shows previews by compiling and running code. You can do a lot of customizing to these previews.
  7. * You can drag UI elements into the preview and Xcode updates the code accordingly.
  8. * VStack and HStack are containers that act like a UIStackView.
  9. * You can edit the UI code and in the Preview. Both update each other accordingly.
  10. * You can use the preview editor to see and modify certain properties, like for instance alignment or text sizes.
  11. * Methods that configure colors, fonts, etc. are called _modifiers_
  12. * To show lists, you don't need delegates or datasources anymore.
  13. * Items in a list should conform to `Identifyable`, so the list can understand which items are coming and going.
  14. * Cells in a list are self sizing by default.
  15. * You can view and filter available modifiers in the library.
  16. * If you want to use a list to navigate to detail views, you should add a `NavigationButton` to the list item and add subviews to the button.  The navigation button also takes an instance of its destination. /TODO: curious whether this is a performance issue; do you really pass an instance as the destination?/
  17. * Views in swiftUI are structs that conform to `View`, this means that views inherit no boilerplate and are passed by value, not reference. The framework aggressively modifies views to make an efficient render tree.
  18. * Views in Swift UI define a small part of your UI.
  19. * A view defines its dependencies.
  20. * When you add an `@State` annotated variable, SwiftUI takes care of the storage of that state. When the state changes, your `body` will be accessed again and the view is rendered again.
  21. * SwiftUI detects that state belongs to a view and refreshes the rendering.
  22. * State variables and models are the source of truth for your entire application.
  23. * `BindableObject` can be used to observe changes on a model. _There will be later talks to go into this_
  24. * A lot of views in apps have a lot of dependencies in terms of models and other views. Lots of shared state is very hard to manage.
  25. * User interactions, background code and completion blocks can cause a lot of problems in UI code because all events can occur in many orders and events can occur multiple times. It's very easy to have UI bugs because of this.
  26. * Because Swift UI uses your data and model as a single source of truth, the view will always reflect the state of your app instead of depending on concurrent stuff going on. This prevents a lot of  UI bugs.
  27. * You can use Groups to provide several previews of a layout, creating a comprehensive state overview.
  28. * You can use a forEach method to loop over items and create a view for every item in a data set, for instance to add an add button above a list of things you could create a list where the first item is static and then use a foreEach to add list items for the regular items in the list.
  29. * You can use an `onDelete` method to implement list item deletion just like you would do in table views by updating the underlying data source when a user performs the delete action.
  30. * Previews allow you to do loads of testing without ever compiling your app.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand