IOS
317 bites tagged IOS — interview questions with model answers, and 60-second explainers.
Run a Core ML image model with Vision
Add the .mlmodel so Xcode generates a class, wrap it in a VNCoreMLModel, run a VNCoreMLRequest via a VNImageRequestHandler, read results off the main queue. Wiring Core ML into Vision for image inference.
Track location continuously in the background
Set desiredAccuracy, distanceFilter, activityType; enable the Location background mode and allowsBackgroundLocationUpdates; request Always authorization. Tuning Core Location for accuracy versus battery and enabling background updates.
Play a remote video with AVFoundation
Wrap the URL in AVPlayerItem, feed it to AVPlayer, render with AVPlayerLayer added to the view's layer (or AVPlayerViewController for controls). Knowing the AVPlayer rendering stack.
Request the user's location one time
Add a usage description to Info.plist, set a CLLocationManager delegate, request when-in-use authorization, call requestLocation, handle didUpdateLocations and didFailWithError. The Core Location permission and one-shot fetch flow.
Animate a SwiftUI Shape morphing point count
Expose a continuous sides value as animatableData so SwiftUI interpolates it, then compute the path from that fractional value each frame. Driving custom interpolation with animatableData.
Build an interruptible custom VC transition
A delegate vends an animator (UIViewControllerAnimatedTransitioning) for the visuals and an interactive controller (UIViewControllerInteractiveTransitioning) driven by a pan to scrub progress and… The custom transition protocol stack.
Diagnose dropped frames during animation
Use Core Animation and color-debug options to spot off-screen passes, blending, and overdraw; cache, flatten, and set shadowPath. Profiling rendering with Instruments and fixing GPU hot spots.
Allow simultaneous pan and pinch gestures
Attach pan and pinch recognizers, set yourself as delegate, return true from shouldRecognizeSimultaneouslyWith, apply translation to center and scale to transform. Simultaneous gesture recognition via the delegate.
Build a custom circular progress bar in UIKit
Draw an arc with UIBezierPath, assign it to a CAShapeLayer path, set lineWidth and no fill, animate strokeEnd 0 to 1. Vector drawing with CAShapeLayer plus strokeEnd animation.
Difference between frame, bounds, and center
Frame and center are in the superview's space; bounds is the view's own space, usually origin zero. A non-identity transform makes frame undefined to read. Coordinate systems and transform effects.
Add shadow and rounded corners to a UIView
CornerRadius needs masksToBounds true, but that clips the shadow; set shadowPath to keep both and stay performant. CALayer shadow and corner properties plus the masksToBounds conflict.
Implicit .animation() vs explicit withAnimation
.animation(value:) animates a view when a tracked value changes; withAnimation wraps the state mutation so all dependent views animate. How SwiftUI ties animation to state changes.
What is an actor and how does it prevent data races
Actors serialize access to mutable state, reachable only via await; compiler blocks unsafe access. Token-refresh actor coalesces concurrent refreshes. Actor isolation as compiler-enforced safety.
How task cancellation works with async/await
Cancellation is a flag, not a kill; check Task.isCancelled or call checkCancellation, URLSession throws CancellationError automatically. Cooperative cancellation in Swift Concurrency.
Add a default header to every URLSession request
Set httpAdditionalHeaders on a URLSessionConfiguration, build the session from it, mention per-request overrides win. Knowing URLSession is configured, not just used. Subclassing URLRequest or mutating every request by hand.
What is @MainActor and why does it matter?
@MainActor is a global actor guaranteeing code runs on the main thread; annotate UI-updating types or methods so post-network state changes are main-thread safe. thread safety for UI updates.
Run two API calls concurrently with async let
Use async let to start two independent fetches that run concurrently, then await both, so total time approaches the slower call rather than the sum. structured concurrency for parallel work.
URLSession data vs download vs upload tasks
Data tasks buffer responses in memory for small API calls; download tasks stream to a file and support background transfers for large files; upload tasks send bodies from data or files and report… choosing the right URLSession task.
Map JSON keys to differently named Codable properties
Declare a nested CodingKeys enum mapping userID to the raw value "user_id", or set the decoder's keyDecodingStrategy to convertFromSnakeCase for blanket conversion. Codable key customization.
Fetch and decode JSON with async/await and URLSession
Call URLSession.shared.data(from:) inside an async throws function, check the HTTPURLResponse status, then JSONDecoder().decode([User].self) and let errors propagate via try. modern networking basics.
Design offline-first sync and conflict resolution
Queue local mutations with timestamps and sync state, push and pull deltas using a change token or updatedAt cursor, and resolve conflicts with a chosen policy like last-write-wins or field-level merge. offline-first sync design.
Bulk-import large JSON into Core Data efficiently
Use NSBatchInsertRequest to write rows directly to the store, bypassing context object materialization, for huge memory and speed wins; limitation is it skips validation, relationships, and does not notify… knowing the batch APIs.
Optimize a slow NSFetchedResultsController screen
Set fetchBatchSize so rows load in pages, use relationshipKeyPathsForPrefetching to avoid per-row faulting round trips, and add indexes matching sort and predicate to make queries fast. Core Data fetch tuning.
Why store auth tokens in Keychain, not UserDefaults?
UserDefaults is an unencrypted plist readable from backups and on jailbroken devices; use Keychain Services, which stores encrypted items with access control; save with SecItemAdd and read with… secure credential storage.
Get IOS bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.