Key | Description |
---|---|
Command + 0 |
Toggle navigator panel |
Command + Option + 0 |
Toggle inspector panel |
Command + Shift + L |
Open object library |
Command + D |
Duplicate object |
Command + Option + Enter |
Toggle preview panel |
Control + I |
Format code |
Option + Click |
Open document |
- Learn how to use playgrounds.
- Learn about variables in Swift that have two types:
let
for immutable andvar
for mutable. - Learn about optionals in Swift and how to unwrap using
if let
.var name: String? // This is an optional string. if let name = name { // Unwrap the optional to ensure it has a value. print("Hello, \(name)") }
- Use backslash for escaping characters.
let name = "John" print("Hello, \(name)") // Hello, John
- Learn about
UIView
andUILabel
and how to display labels in a view.-
UIView
let orangeBox = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) orangeBox.backgroundColor = .orange
-
UILabel
let goodbyeMessage = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) goodbyeMessage.text = "Byeeeee"
-
- Connect button to function by
Control + click
button in storyboard and drag to the function with@IBAction
keyword in swift file. - To get button's text, use
button.titleLabel?.text
. viewDidLoad
function is called when the view is loaded.- Open document by holding
Option
key andclick
on variables, functions. - Center the button using autolayout by adding
Horizontal in Center
andVertical in Center
constraints. - Update misplaced view by selecting yellow arrow in document outline and update the view's frame.
- To open preview, press
Command + Option + Enter
. - To hide/show left sidebar, press
Command + 0
and right sidebar, pressCommand + Option + 0
.
- To create spacing constraints, Click
Add New Constraints
orControl + drag
object to the view. - To edit constraints, Double click on the blue line or edit the constraint's value in the attribute inspector panel.
- Learn how to embed objects in a stack view
- By adding stack view from object library.
- By select multiple objects and select "Embed In".
- Edit alignment, distribution, spacing of stack view via inspector panel
- Autoshrink label for small screen by edit "Autoshrink" value in inspector panel.
- To add images, select "Assets" in project navigator and drag image to set viewer.
- Adjust the size of objects for specific screen using size classes.
- iOS devices have two size classes for width and height that can be either regular or compact.
- By clicking on
+
button in the inspector panel, you can add size classes to that property.
- Testing dark mode by clicking on
Environment Overrides
and select dark mode inApperance
section. - Learn how to use
UITableViewController
. - Use
@IBOutlet
to connect objects in storyboard.@IBOutlet var nameLabel: UILabel! @IBOutlet var locationLabel: UILabel! @IBOutlet var typeLabel: UILabel! @IBOutlet var thumbnailImageView: UIImageView!
- Learn to create action sheet using
UIAlertController
andUIAlertAction
.let optionMenu = UIAlertController(title: nil, message: "What do you want to do?", preferredStyle: .actionSheet) let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) optionMenu.addAction(cancelAction) present(optionMenu, animated: true)
- Use
.actionSheet
to create action sheet and.alert
to create alert dialiog. - Learn closure syntax.
let reserveActionHandler = { (action:UIAlertAction!) -> Void in // Body of the closure. }
- Cell in table view is reusable cell then some state may be persist when it's reused again.
- Learn how to cast objects by using
as!
let cell = tableView.cellForRow(at: indexPath) as! RestaurantTableViewCell
- To hide/show
UIImageView
by setting itsisHidden
property. - Create object by using
struct
and initializer by creatinginit
function(s).struct Restaurant { var name: String var type: String var location: String var image: String var isFavorite: Bool init(name: String, type: String, location: String, image: String, isFavorite: Bool) { self.name = name self.type = type self.location = location self.image = image self.isFavorite = isFavorite } init() { self.init(name: "", type: "", location: "", image: "", isFavorite: false) } }
- Struct can have multiple initializers.
- Create instance of struct without
new
keyword.Restaurant(name: "Traif", type: "American", location: "New York", image: "traif", isFavorite: false)