All bites
The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.
4330 bites
Page 138
Track location continuously in the background
Set desiredAccuracy, distanceFilter, activityType; enable the Location background mode and allowsBackgroundLocationUpdates; request Always authorization.
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.
Display thousands of map annotations efficiently
Enable clustering via clusteringIdentifier, reuse views with dequeueReusableAnnotationView, render clusters with MKClusterAnnotation in viewFor.
Apply a CIFilter to a live camera feed
Use AVCaptureSession with AVCaptureVideoDataOutput, receive CMSampleBuffers in captureOutput via the sample buffer delegate on a serial queue, filter with CIImage, drop late frames.
React to location authorization changed in Settings
Implement locationManagerDidChangeAuthorization, which fires on launch and whenever status changes, read authorizationStatus, and start updates when authorized.
Recognize objects in ARKit with a Core ML model
Pull the frame's capturedImage, run Vision/Core ML off the main thread, raycast the 2D detection point into the scene, add an ARAnchor.
Unit test versus UI test in Xcode
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.
Unit test a ViewModel with a mocked NetworkService
Inject the protocol, supply a mock returning canned data, assert published state transitions.
Testing async code and completion handlers in XCTest
Create an expectation, fulfill it inside the completion handler, call wait with a timeout, or use async test methods.
Locating XCUITest elements without accessibility identifiers
Query by type, label, predicate, or index; chain queries to narrow scope.
Code coverage and its pitfalls
It measures executed lines, surfaces untested paths, and guides where to add tests.
Diagnosing and stabilizing flaky XCUITests
Identify timing races, animations, network variance, and shared state; fix with expectations, controlled launch state, and isolation.
Driving app state via launch arguments in XCUITest
Pass launchArguments and launchEnvironment, read them at startup to seed auth and flags, bypassing slow UI steps.
Adding a Swift Package dependency in Xcode
Add via File menu, paste the repo URL, choose a version rule like up-to-next-major, link the product to your target.
Package.swift manifest: library vs executable products
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.
Modularizing a monolithic iOS app
Extract low-dependency, high-reuse leaf code first behind clear interfaces, enforce boundaries, iterate inward.
Static library versus dynamic framework linking
Static code is copied into the executable at build time; dynamic is loaded at launch by dyld. Trade-off: static bloats the binary but avoids load cost; many dynamic frameworks slow launch.
Developing a local Swift Package alongside an app
Add the package as a local dependency by dragging its folder into the project or workspace, so Xcode references the source on disk and rebuilds edits immediately.
App ID, provisioning profile, and signing certificate
The certificate proves who you are, the App ID identifies the app and its capabilities, and the provisioning profile binds certificate, App ID, and allowed devices so iOS trusts the install.
Archiving and uploading a build to TestFlight
Select a real-device or Any iOS destination, Product Archive, then in the Organizer distribute to App Store Connect, where the build appears for internal TestFlight testers after processing.