0% found this document useful (0 votes)
21 views19 pages

iOS App Dev W - App Brewery

Uploaded by

yanichik20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views19 pages

iOS App Dev W - App Brewery

Uploaded by

yanichik20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Xcode Tour

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

4. app icon generator: to create images of different sizes


5. create icons with canva
6. margin: defined NOT as the edge of the phone but rather the difference between the
edge of the view and it's superview. this value can be changed but by default it is set at
16px from the edge of the phone (relative to the left and right edges)
7. number of lines to zero (0) allows infinite number of lines
8. IBAction vs IBOutlet
a. IBOutlet is used to create a connection between an interface element and a
property in your code, while IBAction is used to create a connection between an
interface element and an action method in your code.
9.

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:

3. String interpolation using with template literals using \():


print("hi \(2+3) guys") => "hi 5 guys"
4. let vs var

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

c. Force unwrapping: optional!


d. Check for nil value
if optional != nil {
optional!
}
e. Optional binding
if let safeOptional = optional {
safeOptional
}
f. Nil coalescing op: optional ?? defaultValue
g. Optional chaining: optional?.property
8. Operators
a. range operators

i. closed-range operator includes nums on both sides of range: ...


1. Int.random(in: lower ... upper)
ii. half-open range operator includes lower but not upper bound: ..<
9. Methods
10. Attributes

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

b. Inheritance ONLY WORKS for classes


c. Protocols can be adopted by structs and/or classes
d. When class needs to inherit from superclass, the superclass needs to come first,
followed by any other classes and/or protocols

e. Extensions allow you to extend or redefine


14. Function Overloading
a. If the method allows it, you can use function overloading to provide multiple
implementations of the same method with different parameters or types.
b. Example:
i. class MyClass {
func performBehavior() {
print("Original behavior")
}
func performBehavior(customValue: Int) {
print("Customized behavior with value
\(customValue)")
}
}
let object = MyClass()
object.performBehavior() // Output: "Original behavior"
object.performBehavior(customValue: 42) // Output:
"Customized behavior with value 42"
c.
15. External Parameter Name
a. aka parameter labels or argument label or external parameter name
b. In Swift, the underscore _ in the function signature func
textFieldDidEndEditing(_ textField: UITextField) indicates that
the parameter should not have an external parameter name.
c. In Swift, by default, function parameters have both an internal parameter
name (used within the function body) and an external parameter name
(used when calling the function). However, by using an underscore _ as
the external parameter name, you indicate that the parameter should be
called without an external name.
d. In the example you provided, the textField parameter does not have an
external name. When calling the textFieldDidEndEditing method, you
would only need to provide the value for the textField parameter, without
explicitly specifying an external parameter name.
e. Ex: textFieldDidEndEditing(myTextField)
f. In Swift, you have flexibility in choosing parameter labels (external
parameter names) for your functions, but there are some conventions and
guidelines to consider:
Descriptive Labels: It's generally a good practice to use descriptive labels
that make the purpose of the parameter clear when calling the function.
For example, if you have a function to set a person's name, you might use
set(name:) as the function name with an external parameter label of
name.
Default Parameter Labels: If you don't provide an external parameter
name, Swift uses the local parameter name as the default external name.
For instance, func setName(_ name: String) allows you to call it without
the label: setName("John").
Explicit External Names: You can specify an explicit external parameter
name if you want to provide a clear and self-explanatory label. For
example, func setAge(to newAge: Int) uses to as an external name.
Omitting External Names: If you don't want an external name, you can use
an underscore (_) as a placeholder. For example, func increment(_ by:
Int) allows you to call it as increment(5) without specifying the
parameter name.
Variadic Parameters: When using variadic parameters (those that accept
multiple values), the external parameter name is used for each value. For
example, func average(of numbers: Double...) uses of as the
external name, so you'd call it like average(of: 1.0, 2.0, 3.0).
Function Overloading: You can have multiple functions with the same
base name but different external parameter names to provide different
ways of calling the function. This is called function overloading.
In summary, you have the freedom to choose parameter labels that make
your code more readable and self-explanatory. However, it's essential to
follow naming conventions, use clear labels, and consider the context and
purpose of your functions to create clean and maintainable code.
g.
16. Networking
a.
17. Closures
a. anonymous functions that can be passed around and used. closures can
capture and store constants or variables from the context in which they're
defined
b. closures are reference types. This means that when you assign a closure
to more than one variable they will refer to the same closure. This is
different from value type which make a copy when you assign them to
another variable or constant.
c. implicit return values -> Closures that have only one statement will return
the result of that statement. To do that simply omit the return keyword
d. 3 types of closures
i. global functions – they have a name and cannot capture any values
ii. nested functions – they have a name and can capture values from
their enclosing functions
iii. closure expressions – they don’t have a name and can capture
values from their context
e. when inside closure, must use self explicitly to call on class function within the
class
18. Enums
a. https://www.hackingwithswift.com/read/0/14/enumerations
19. Codable, Encodable, Decodable
a. Encodable: swift type Encoding into external representation
b. Decodable: external representation converting to swift type
20. TImers
a. timer tutorial by hacking with swift

UI for iOS

1. Header vs Section Header


a. In iOS development, "header" and "section header" refer to different components
used in various UIKit classes for creating user interfaces, primarily in the context
of UITableView and UICollectionView. Here's the difference between them:
​ Header:
● A "header" generally refers to a view or a piece of content that appears at
the top of a table view or collection view. It typically provides a title or a
brief description for the entire list or collection below it.
● In UITableView, a "header" is created using the tableHeaderView
property. This is a single view that appears at the top of the table view
and remains visible as you scroll through the content.
● In UICollectionView, a "header" can be created using supplementary
views, specifically the UICollectionReusableView subclass designated as
a header. Headers are typically associated with a specific section in the
collection view.
​ Section Header:
● A "section header" is a specific type of header used in UITableView and
UICollectionView to group and label items within sections. It appears at
the top of each section and provides a title or additional information
relevant to that section.
● In UITableView, section headers are created using the
tableView(_:viewForHeaderInSection:) method and the
tableView(_:heightForHeaderInSection:) method to customize the
appearance and size of section headers.
● In UICollectionView, section headers are created similarly using
supplementary views with specific reuse identifiers designated as
headers. You use the
collectionView(_:viewForSupplementaryElementOfKind:at:) method to
provide the view for a section header and the
collectionView(_:layout:referenceSizeForHeaderInSection:) method to
specify its size.
In summary, the key difference lies in the context and purpose:
● A "header" is a more general term that can refer to any content at the top
of a list or collection view.
● A "section header" is a specific type of header used to label and provide
context for individual sections within a UITableView or UICollectionView.
They are used to organize and differentiate content within the view.

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

blocking the main thread and keeping the UI responsive.

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.

c. By requiring explicit use of DispatchQueue.main.async, Swift and iOS give you

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

practice for UI thread safety.

d. In essence, the use of DispatchQueue.main.async is a design choice that places

responsibility on the developer to make explicit decisions about UI thread

management, keeping the code clear and predictable. While it might seem less

convenient in some scenarios, it provides control and flexibility when handling

asynchronous tasks and UI updates in iOS applications.


8.

You might also like