More in iOS & Swift — page 3
Modularizing a monolithic iOS app
WHAT IT TESTS: incremental modularization strategy. OUTLINE: extract low-dependency, high-reuse leaf code first behind clear interfaces, enforce boundaries, iterate inward.
Package.swift manifest: library vs executable products
WHAT IT TESTS: understanding SPM package structure. OUTLINE: the manifest declares name, targets, dependencies, and products; a library is consumed by other code while an executable produces a runnable binary with an entry point.
Adding a Swift Package dependency in Xcode
WHAT IT TESTS: basic SPM workflow knowledge. OUTLINE: add via File menu, paste the repo URL, choose a version rule like up-to-next-major, link the product to your target.
Driving app state via launch arguments in XCUITest
WHAT IT TESTS: setting up test preconditions cheaply. OUTLINE: pass launchArguments and launchEnvironment, read them at startup to seed auth and flags, bypassing slow UI steps.
Diagnosing and stabilizing flaky XCUITests
WHAT IT TESTS: handling nondeterminism in UI automation. OUTLINE: identify timing races, animations, network variance, and shared state; fix with expectations, controlled launch state, and isolation.
Code coverage and its pitfalls
WHAT IT TESTS: understanding coverage as a signal, not a goal. OUTLINE: it measures executed lines, surfaces untested paths, and guides where to add tests. RED FLAG: treating 100 percent as proof of correctness or writing assertion-free tests just to inflate…
Locating XCUITest elements without accessibility identifiers
WHAT IT TESTS: navigating the element query hierarchy. OUTLINE: query by type, label, predicate, or index; chain queries to narrow scope. RED FLAG: relying on brittle absolute indices or visible label text that breaks under localization and layout changes.
Testing async code and completion handlers in XCTest
WHAT IT TESTS: knowledge of waiting for asynchronous work in tests. OUTLINE: create an expectation, fulfill it inside the completion handler, call wait with a timeout, or use async test methods.
Unit test a ViewModel with a mocked NetworkService
WHAT IT TESTS: dependency injection and test isolation. OUTLINE: inject the protocol, supply a mock returning canned data, assert published state transitions. RED FLAG: hitting the real network or testing the concrete service instead of the ViewModel.
Unit test versus UI test in Xcode
WHAT IT TESTS: The scope and tooling difference between test types. OUTLINE: Unit tests (XCTest) exercise code logic in-process and fast; UI tests (XCUITest) drive the app through the accessibility layer, slower and end-to-end.
Recognize objects in ARKit with a Core ML model
WHAT IT TESTS: Combining ARKit, Vision, and Core ML plus 2D-to-3D mapping. OUTLINE: Pull the frame's capturedImage, run Vision/Core ML off the main thread, raycast the 2D detection point into the scene, add an ARAnchor.
React to location authorization changed in Settings
WHAT IT TESTS: Observing authorization changes via the delegate. OUTLINE: Implement locationManagerDidChangeAuthorization, which fires on launch and whenever status changes, read authorizationStatus, and start updates when authorized.
Apply a CIFilter to a live camera feed
WHAT IT TESTS: Capturing raw frames and the queue discipline. OUTLINE: Use AVCaptureSession with AVCaptureVideoDataOutput, receive CMSampleBuffers in captureOutput via the sample buffer delegate on a serial queue, filter with CIImage, drop late frames.
Display thousands of map annotations efficiently
WHAT IT TESTS: Annotation clustering and view reuse in MapKit. OUTLINE: Enable clustering via clusteringIdentifier, reuse views with dequeueReusableAnnotationView, render clusters with MKClusterAnnotation in viewFor.
Run a Core ML image model with Vision
WHAT IT TESTS: Wiring Core ML into Vision for image inference. OUTLINE: 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.
Track location continuously in the background
WHAT IT TESTS: Tuning Core Location for accuracy versus battery and enabling background updates. OUTLINE: Set desiredAccuracy, distanceFilter, activityType; enable the Location background mode and allowsBackgroundLocationUpdates; request Always authorization.
Play a remote video with AVFoundation
WHAT IT TESTS: Knowing the AVPlayer rendering stack. OUTLINE: Wrap the URL in AVPlayerItem, feed it to AVPlayer, render with AVPlayerLayer added to the view's layer (or AVPlayerViewController for controls).
Request the user's location one time
WHAT IT TESTS: The Core Location permission and one-shot fetch flow. OUTLINE: Add a usage description to Info.plist, set a CLLocationManager delegate, request when-in-use authorization, call requestLocation, handle didUpdateLocations and didFailWithError.
Animate a SwiftUI Shape morphing point count
WHAT IT TESTS: Driving custom interpolation with animatableData. OUTLINE: Expose a continuous sides value as animatableData so SwiftUI interpolates it, then compute the path from that fractional value each frame.
Build an interruptible custom VC transition
WHAT IT TESTS: The custom transition protocol stack. OUTLINE: A delegate vends an animator (UIViewControllerAnimatedTransitioning) for the visuals and an interactive controller (UIViewControllerInteractiveTransitioning) driven by a pan to scrub progress and…