A database on your device that builds a graph of objects. Graph is automatically serialized and put into database. Create "fetches" to access stuff that are turned into DB queries.
Back
Multi-threading in iOS
Front
Run multiple parts of an app simultaneously, handle long-running activities, and block activities.
Back
How to make a Table View
Front
1.) Select and drag in a table view to your controller
2.) Create an outlet for it in your view controller class
3.) Make view controller class conform to UITableViewDelegate, UITableViewDataSource protocols. First one is a delegate for the view and display, second one is a delegate for the data of the view.
4.) add didSet {} to the Table View outlet >> put in .delegate = self, and .dataSource = self. This sets the delegates to the view.
5.)
- func numberOfSections(...) -> Int {} defines the number of sections (demo sets it to 1).
- func tableView(...) -> Int {} defines number of rows in each section.
- func tableView(...) -> UITableViewCell {} defines the data in the cells.
6.) Make a cell class that is a subclass of UITableViewCell.
7.) Increment the prototype cells counter to add a cell. Put whatever you want in it.
8.) Select the prototype cell and in the attribute inspector choose custom class = the cell class you just made.
9.) Make outlets in your cell class for the items in your prototype cell (by dragging them).
10.) In the func tableView() -> UITableViewCell {}, create var = tableViewOutlet.dequeueReusableCell(...) ->
withIdentifier: <your cell class>
for: indexPath
11.) Downcast from the var you made (default cell) to your cell and in the if statement you can modify the outlets to display data.
Back
Main Queue (serial)
Front
let mainQ = DispatchQueue.main
All UI activity here (no long-running, non-UI stuff).
Back
Table View
Front
A single column of vertically scrolling content divided into rows. Some rows can be sectioned.
**UIScrollView subclass
**Example app: Contacts
Back
Lifecycle: Creation
Front
Creation from xib (XML nib)
awakeFromNib() called very early
Back
How to access data in Core Data
Front
let cntr = (UIApplication.shared.delegate as! AppDelegate).persistentContainer
let context: NSManagedObjectContext = cntr.viewContext
Back
UTI
Front
Universal Type Identifier represents types of files that you can handle such as com.adobe.pdf.
CFBundleTypeRole and LSHandleRank say how you handle it.
Back
Global Queue (concurrent)
Front
let backgroundQ = DispatchQueue.global(qos: <...>)
In <...> you can have:
.userInteractive = high priority, short
.userInitiated = high priority, longer
.background = not user created, slow
.utility = system maintenance
Back
UITextField
Front
Takes input from the user with the on-screen keyboard. User inputs text when the becomeFirstResponder() method is called either by tapping the text field or calling the method directly. resignFirstResponder() closes the keyboard, such as when the user hits "done".
Decides whether to do normal processing on <return> key. Must resign first responder here.
Back
viewWillLayoutSubviews, viewDidLayoutSubviews
Front
Boundaries about to change or have changed.
Back
Grand Central Dispatch
Front
Achieve multi-threading with queues, lock-based synchronization, barriers, etc.
Back
viewWillTransition
Front
Used to handle auto-rotation.
Back
Lifecycle: viewDidLoad
Front
Primary place to do app-specific setup since the view is in place.
- outlets are set
- bounds are not set
- called once
Back
How to create a UIDocument
Front
1) define URL
2) call the only init
3) set your model
var url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
url = url.appendingPathComponent("foo.bar")
let myDocument = Doc436(fileURL: url)
Back
Core Data Types
Front
Numbers = Double, Int, etc.
Binary data = NSData's
Dates = NSDate's
Relationships
= To-many are NSSet's
= To-one are NSManagedObject's
Back
File System Sandbox
Front
1) Privacy
2) Security
3) Cleanup
Back
Elements of Core Data
Front
Entities = Classes (tables)
Attributes = Properties (columns)
Relationships = References (foreign keys)
**Access through an NSManagedObjectContext
from a NSPersistentContainer**
Back
UIDocumentBrowserController
Front
Controls the menu where you can access user documents. Perform functions like opening, closing, renaming, moving, iCloud, Drobox, etc. You can define your own document template and handle them.
Back
Querying Core Data
Front
How to make a query:
= create the request request: NSFetchRequest let fetchRides: NSFetchRequest<Ride> = Ride.fetchRequest()
NSSortDescriptors for ordering of results - set of descriptors [first-sort, second-sort]
NSPredicate boolean for filtering
Back
MapKit
Front
Makes it easy to bring up a map:
- show specific region
MKMapView.setRegion(..)
- current position (option when adding
mapview in storyboard)
Options for type .standard or .satellite.
Add to the map via annotations or overlays.
Back
Document states
Front
1) .open = document is open and ready
2) .closed = document is closed
3) .savingError = override handleError to see why
4) .editingDisabled = the document cannot currently be edited
5) .progressAvailable = how far document is in getting loaded (check progress var)
6) .inConflict = someone else edited this document (iCloud)
Back
Lifecycle: viewDidAppear
Front
View is on-screen. Use for UI tasks (animations, GPS, etc)
Back
dataSource
Front
A tableView property that provides data to the view. Remember that *views don't own their data* it acts like a delegate.
Back
Static Cells vs Dynamic Prototypes
Front
In a Table View, if "static cells" is selected it means the view won't scroll.
If "Dynamic Prototypes" is selected then the view will scroll since it's dynamically mapping content to the views.
Back
How to store distances & locations
Front
- Store an array of gps locations
- Can get distances between last locations in
meters (.distance)
- You can also have a list of locations loaded in
via a plist. Must be stored as Data and
decoded.
Back
How to use Core Data
Front
1) Start project with core data selected.
2)
Back
Lifecycle: viewDidDisappear
Front
View is on-screen but about to go. Wind things down (like animations, GPS, etc.)
Back
Prototype Cells
Front
A default cell that new cells are cloned from.
In table view attr inspector, increment "Prototype Cells" to generate one.
Back
MKMapViewDelegate, MKAnnotation
Front
View controller class must conform to MKMapViewDelegate. Make an object that conforms to MKAnnotation.
Add annotation object to mapview w/ addAnnotation(_:). Next, add implementation for mapView(_: viewFor:) to provide view for the
annotation.
Back
Collection View
Front
Organizes data into individual items, which can then be grouped into sections for presentation. (An item is the smallest unit of data you want to present). Presents these items using cells.
**UIScrollView subclass
Back
URLSessions
Front
Fetch contents of an http URL into a Data.
*NOT on the main queue*
Back
UITextInputTraits
Front
A protocol implemented by UITextField that modified keyboard appearance.
Back
URLs in iOS
Front
Can be local through (usually the "main") bundle:
- URL = Bundle.main.URL(forContent: "pretty", withExtension: "jpg"
Can be remote through normal URL:
- URL = URL(string: "http://kelehers.me/orion.jpg")
Usage in file system dirs:
let url: URL = FileManager.default.url(
for directory:.documentDirectory,
in domainMask: .userDomainMask
appropriateFor: nil,
create: true
)
// always .userDomainMask on iOS //
Back
APFS
Front
Apple File System:
- optimized for solid-state drives
- copy-on-write
- deduplication
- zero-cost copies
- reliability
- file system snapshots (not yet used by Time
Machine)
- dynamic volume sizing
Back
Serial vs Concurrent queues
Front
Serial = single-thread
let serialQ = DispatchQueue(label: "MySerial")
Concurrent = multi-thread
let concurrentQ = DispatchQueue(label: "MyConcurrent", attributes: .concurrent)
Back
UIDocument
Front
An abstract base class. Must be subclassed to use and implement methods tht read/write Data. Used if an app stores "documents" from user perspective and iOS can manage the storage.
- All interaction with storage, including
DropBox, Drive, iCloud...
- Async API
- Autosaving
- Visible in Files app
Back
CLLocationManagerDelegate
Front
Location manager delegate that must be made superclass of view controller class and implemented.
.desiredAccuracy = accuracy of GPS tracking.
More accurate = more power consumption.
Back
Add/Delete/Save to Core Data
Front
Add = must give context for a new object
let ride = Ride(context: AppDelegate.viewContext)
ride.name = name
ride.when = Date()
ride.distance = distance
Save = try context.save()
Del = managedObjectContext.delete(_ object: location)
Back
Reusable Cells
Front
dequeueReusableCell(withIdentifier:) grabs a cell from the reuse pool.
Back
Exported UTI
Front
Custom document types defines by your app. Key is public.filename-extension and value is the name of your document type.
Back
Lifecycle: viewWillAppear
Front
Right before view appears on screen.
- called many times
- use for changes between screens
*view doesn't always appear*
Back
How to persist a UIDocument
Front
Turn it into a Data to be persisted:
override func contents(forType typeName: String) throws -> Any { }
Retrieve your document from a Data:
override func load(fromContents contents: Any,
ofType typeName: String?) throws { }
Back
Core Location
Front
Framework for working with location services. Must authorize first with user (by asking or hitting a button).
Must add NSLocationAlwaysUsageDescription in info.plist:
.authorizedAlways
.authorizedWhenInUse - stops when app
closed (not background)
Back
Lifecycle: viewDidDisappear
Front
View is gone. Rarely used, maybe to de-allocate memory.