iOS App Dev W - App Brewery
iOS App Dev W - App Brewery
1. status bar
2. navigator pane
3. inspector pane
4. attribute inspector
5. size inspector
6. document outline
a. layered such that position of entity one on top of the other relates to how it is
actually layered in the application
7. debug pane (Shortcut: Cmd+Shft+Y)
8. size class area
9. Xcode Shortcuts
a. Cmd + (1-7): switch navigators
b. Cmd + 0: toggle navigators
c. Cmd + alt + J: filter in navigator
d. Cmd + enter: show standard editor
e. Cmd + alt + ctrl + enter: show assistant editor
f. Cmd + alt + shift + enter: show version editor
g. Cmd + shift + Y: toggle debug area
h. Cmd + alt + (1-6): switch inspectors
i. Cmd + alt + 0: toggle utilities
j. Cmd + shift + L: search in library
k. Cmd + R: build and run in simulator
l. Cmd + shift + H: open simulator without building
m. Ctrl + alt + 6: toggle document outline
n.
10. Launch storyboard vs Main: launch determines what you first see when the app is
launched, whereas main is the actual app
11. Multiple Cursors
a. To add a new cursor, hold Control and SHIFT then click.
12.
Architecture
1. MVC
a. Model: data and logic
b. View: UI
c. Controller: mediator
i. responsible for telling other components WHAT TO DO
d.
Design UI
1. iphone resolutions
2. color palettes for designers at ColorHunt
3. points vs pixels
iOS Lifecycle
1. Delegate
a. Delegate gets notified when event occurs. Need to set who the delegate is
2. Navigation Controller
a. adding nav controller creates a nav bar at top of view at the selected VC and all
the downstream VCs
b. creates navigation controller stack
c. Segues
i. Action-based segues, like an action from button click to view VC, are
automatically triggered at click of button
ii. Direct VC-to-VC segues need an identifier so that authentication can be
attached and are triggered manually from the code
d. Nav Controller vs Nav Item
i.
Programmatic Concepts
1. IB Outlet: interface builder outlet
a. interface board = interface builder: where app design made
Swift
1.
2. # used for:
5. Randomize
a. Int.random(in: 1...10) -> creates random number within range 1-10
inclusive
i. alternatively, can use Int.randomElement()
b. Int.random(in: lower ..< upper) or Float.random(in: lower ..<
upper)
c. array.shuffle() -> in-place shuffle of order of elements inside array
i. array.shuffled() -> returns shuffled version of array
6. Data types
a. Strings MUST use double quotes ""
7. Optionals
a. purpose of optionals is to safeguard us from situation where we try to
use/manipulate a variable
b. Optional binding & optional chaining to unwrap an optional
a.
11. Structs vs Class
a. https://docs.swift.org/swift-book/documentation/the-swift-programming-language/
classesandstructures/
b. Choosing between structs and classes
c. struct unable to inherit like classes
d. structs include embedded initializer vs class must include init IFF the defined
properties are not initialized with values
e. classes are passed by reference, while structs are passed by value
i. to create actual copy of class: need to initialize as did with original
f. structs require use of "mutating" keyword for methods that mutate any
properties
g.
h. Because structures are value types—unlike classes—local changes to a
structure aren’t visible to the rest of your app unless you intentionally
communicate those changes as part of the flow of your app.
i. Computed Property
// computed property: must be a var b/c it can change
var conditionName: String {
switch conditionId {
case 200...232:
return "cloud.bolt"
case 300...321:
return "cloud.drizzle"
default:
return "sun"
}
}
j. Type vs Instance properties of Struct
i. struct MyStruct {
let instanceProp = "instance"
static let typeProp = "type"
}
1. to access instance property, MUST first create instance
a. let myInstance = MyStruct()
print(myInstance.instanceProp)
2. to access type property, can do so DIRECTLY
a. print(MyStruct.typeProp)
k.
12. Swift Memory Management
a. Swift memory management uses ARC (automatic reference counting) to retain or
release objects in memory. A strong reference (the default) adds 1 to the ARC
and a weak reference does not increase the count at all. Having 2 objects each
have a strong reference to the other, creates a retain cycle where neither object
will be released, creating a memory leak, so you will need to read up on this in
the future since it is not covered in detail in the course. At this point in the course,
go with the suggested weak reference that Xcode automatically fills in for things.
13. Protocols & Extensions
a. Protocol is a set of requirements that a class or struct MUST adopt if they are
listing that protocol as a dependent
UI for iOS
Package Managers
1. CocoaPods (best), Swift Package Manager (by Apple), Carthage (poor experience)
2.
xCode
3. plist
a. https://developer.apple.com/library/content/documentation/General/Reference/I
nfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html
4. Dark Mode
a. to switch bet dark/light modes need to use system colors or colors assigned for
diff roles such as label color - auto adaption will not work with custom color
i. can create custom colors that adapt to dark/light modes by creating a new
color set inside Assets.xcassets
5. Targets, Namespaces, Modules, Access Control
a. Symbols within a module have access to each other based on their access
control level (public, internal, fileprivate, private). Symbols marked as internal are
accessible within the same module, while public symbols can be accessed from
other modules that import the module.
b. Creating a new Target
i. Creating a new module in Swift involves creating a new target in your
Xcode project. This can be an iOS app target, a framework target, or a
library target, depending on your use case. Here's a step-by-step guide
on how to create a new module using Xcode: Open Xcode: Launch
Xcode, and open the project where you want to create the new module.
Navigate to Targets: In the Xcode project navigator, select your project
(top-level item) to show the project settings. Then, select your project's
name under "Targets". Add a New Target: Right-click (or Control-click) the
project's name and choose "New Target..." from the context menu. Select
a Template: Choose the template that corresponds to the type of module
you want to create. The available templates include:
1. "iOS" → "App": Creates a new iOS app target.
2. "iOS" → "Framework & Library": Creates a new framework or
library target.
Configure the New Target: Provide the necessary information for your
new module, such as its name, organization, bundle identifier (for app
targets), and other settings. Confirm Creation: After configuring the
settings, click the "Finish" or "Create" button to create the new
target/module. Customize the Module: Depending on the type of target
you chose, you'll now have a new module. You can add Swift files,
resources, classes, structs, functions, and other code specific to your
module's purpose. Access Control and Import: Remember that when
working with multiple modules, you may need to use the public or internal
access control modifiers and the import statement to make symbols
accessible in other modules. Build and Test: After adding code to your
new module, build and test it to ensure that everything works as
expected.
ii.
6. Common Errors
a. “Login View Controller“ is unreachable because it has no entry points, and no
identifier for runtime access via -[UIStoryboard
instantiateViewControllerWithIdentifier:].
i. No segue exists to enter the view controller (aka screen). Need to create
one in code or on storyboard with the arrow
b.
Questions
1. optional type
2. error: "value of optional type 'String?' must be unwrapped to a value of
type 'String'."
3. unwrapping an optional
4. forced unwrapping
5. optional binding
6. nil coalescing
7. When calling a UI update inside a completion handler of a networking task, why doesn't
the iOS switch automatically to the main thread to update UI (since the networking task
is done)?
a. The reason it doesn't automatically jump to the main thread is due to the way
asynchronous code execution works in Swift and iOS. When you perform a
networking task or any other asynchronous operation, the completion handler for
that operation may run on a background thread or a different dispatch queue to avoid
b. The system doesn't automatically switch to the main thread for UI updates because it
cannot make assumptions about your code's intentions. For example, you might have
multiple asynchronous tasks running concurrently, and switching to the main thread
for each one of them could introduce additional complexity and potential
performance issues.
control over when and where you want to update the UI. This approach ensures that
UI updates are done intentionally and on the main thread, which is the recommended
management, keeping the code clear and predictable. While it might seem less