Sound #
- Provide data to OS
- OS decices, what to show (or if anything is shown at all)
- => best practice: supply as much info as possible
AVAudioPlayer
- Play audio (from file or buffer)
- Control volume, panning, looping, ...
AVAudioSession
: Intermediary between the app & OS- Categories:
ambient
: Audio is non-primary (app works without sound): Instagram, Reddit, ...soloAmbient
: Ambient, but max. 1 source can playplayback
: Controls appear; for example in a music playerrecord
,playAndRecord
: Recording (not in the Seminar)
- Categories:
- "Now playing"
- Update
MPNowPlayingInfoCenter.nowPlayingInfo
(Dict) - No idea which keys to use for that
- Update
Haptics #
- Uses
UIFeedbackGenerator
; three subclasses:UIImpactFeedbackGenerator
: when UI element collides with something, something snaps into place, ...UISelectionFeedbackGenerator
: when a change in selection occursUINotificationFeedbackSelection
: indicate success, failure, or warning
- Guidelines:
- Use according to documented meaning
- Be consistent
- Accompany with sound & visuals
- Give option to turn haptics off
- Usage:
1var generator = UIImpactFeedbackGenerator(style: .heavy)
2generator.prepare()
3generator.impactOccured()
4generator = nil // Release to allow TapticEngine to sleep
Rich articles #
UILabel
: Read-only labelsUITextView
: Scrollable, multi-line - supports text editing &NSAttributedString
sNSAttributedString
: String that contains attributes (like Markdown, HTML, ...)NSParagraphStyle
: Style of anNSAttributedString
's segment- Editable subclass:
NSMutableAttributedString
, usesNSMutableParagraphStyle
- Use-cases: Images in text, rendering HTML (using own styles)
WKWebView
: Render Website inside of your app- Integrates into your app (unlike
SFSafariViewController
, which essentially opens Safari)
- Integrates into your app (unlike
ARKit #
Requirements:
- iOS 11.0 or later
- A9 processor or later
- Camera access permission
ARSession
: Controls camera & motion, performs image analysisARConfiguration
: determines camera & tracking algorithm- Back Camera: WorldTracking (Plane/image/object detecion)
- Front Camera: FaceTracking
- Use
ARCoachingOverlayView
for onboarding instructions - Anchors: Identify item positions
- Options:
ARPlaneAnchor
,ARObjectAnchor
,ARBodyAnchor
,ARBodyAnchor
(track position & movement of human body),ARFaceAnchor
(face detection, needs front-facing camera),ARImageAnchor
- Options:
- Rendering views:
ARSCNView
("AR-Scene View", from SceneKit)ARView
: RealityKitARSKView
: SpriteKit- Custom Metal rendering
- Use
ARRaycastQuery
&ARRaycastResult
for raycasts
MapKit #
Embed maps (with custom annotations)
MKPointAnnotation
: Add annotations (balloon-shaped)- Customaisable Color, Title, Icon, ...
- Can cluster
- Overlays: geometric shapes (Circles, Lines, Images, Text, Polygons)
- GeoJSON: Schema for location data (JSON-based)
- MapKit has a parser
- Can be used for indoor maps
Features requiring Apple Services #
- Local Search (search around your current location)
- Look Around (aka Streetview)
- Navigation (no customization options)
Core Image #
- Import different images, apply filters, find prominent features
CIImage
: Image dataUIImage
: Picture, image as complete drawingUIImageView
: Renders picture
Filters (CIFilter) #
- Apply to CIImage(s): n CIImages to one
- Examples: Blur, Sharpen, ...
- Can be combined into one
- Write custom ones in GLSL
CIDetector #
- Identifies notable features (
CIFeature
s) - Examples: Faces, Rects, QR-Codes, Text
- On Image or Video
- Heavy constructor, make sure to reuse
Advanced Functions #
CIContext
: memory management, hardware comm.CIColor
CIRender
: render settingsCIPlugin
Advanced SwiftUI #
- GeometryReader: Get size & position of object
- Layout priorities: determine sizes
- Fixed sizes
- Alignment guides: defaults to
.center
(other options:.bottom
,.firstTextBaseline
, ...)- Supports
computeValue
as parameter - Can implement custom alignments
- Supports
SpriteKit #
- For game devs that don't know about game engines
SKScene
: contains tree ofSKNode
s- Load scenes from
.sks
file - Anchor Points are variable (the point to rotate around)
UIResponer
: touch/press/motion/remove-control eventsSKAction
: modify nodes (animated)SKPhysics
: physics simulation
Core Animation #
Layers #
- Base element:
CALayer
s - Can have subelements
- Masks, cornerRadius
Animations #
- Use
.fromValue
&.toValue
- Target:
.keyPath
.isRemovedOnCompletion
- Start with
layer.add(animation)
- Uses
CIPath
s andCIShape
s for specification CADisplayLink
: write your ownupdate
function
WatchOS #
- Limitations: Size, Battery
- Differing sensors
- Dependent (companion) vs. independent app
Guidelines #
- Keep interactions short
- Max 2/3 controls per row
- Use notifications
WKInterface & SwiftUI #
WKInterface
: (Limited) UIKit clone for watchOS - deprecated- SwiftUI: preffered, no watch-specific code
Connectivity #
- Use
WCSession(Delegate)
: WiFi or Bluetooth - Works on dictionaries
sendMessage
: immediatetransferFile
: send file, might just not send if size is too largeupdateApplicationContext
:transferUserInfo
:
Working with files #
- Display files:
UIDocumentBrowser
(local & cloud documents)
FileManager #
- Create/read/update/delete
- Check existance
- Copy
- Can't append
FileHandle #
- Read/write/update
UIPresentationController #
- Handles transitions between ViewControllers
- Examples:
UISheetPresentationController
,UIPopoverPresentationController
Custom PresentationController #
- TransitioningDelegate: selects PresentationController, AnimationController
- PresentationController: Add/remove views
- AnimationController: Perform animations, define duration
- Use UIPercentDrivenInteractiveTransition (instead of AnimationController) for interactive transition
- Respect device type:
UIAdaptivePresentationControllerDelegate
CoreData #
- Persist data
- Uses
PersistentContainer
for storage (SQLite, XML, CloudKit, ...) - Tracks relations (delete rules: none, nullify, cascade, deny)
- Create model in XCode
- Entity (table), Attributes (column) & Managed Objects (row)
- Use
NSFetchRequest
s for queries,NSPredicate
s for filtering
Combine #
- Pub-sub (for async events)
- Can publish failures (errors)
- Build using
.publisher(for: ...)
,Subscribers.Assign(object: ..., keyPath: ...)
- Custom publishers:
Publisher
protocol
Operators #
-
.subscribe(_: Subscriber)
-
.receive(on: Scheduler)
-
.sink() {...}
: Receive to closure -
.assign(to: path, on: object)
: update variable -
.map
-
.tryMap
-
.mapError
-
.encode
/.decode
-
.filter
-
.removeDuplicates
-
Zip
-
Combine latest
Integrations #
- SwiftUI: @ObservedObject, @Published
- Foundation (URLSession, NotificationCenter, Timer)
- CoreData: FetchedRequest
CreateML/CoreML #
- Predict, customize, encrypt, personalize
- Runs on-device
- Convert other models using Python script
- CreateML: train from example input sets