Skip to content

iOS (Swift and SwiftUI)

Scope: native iPhone and iPad apps written in Swift with SwiftUI, in the Swift 6 language mode. The App Store has required Xcode 26 and the iOS 26 SDK since 28 April 2026 (MOBGAME-5), and the current release is Xcode 27, with Swift 6.4 and the iOS 27 SDK. Most rules also apply to UIKit code and to Apple's other platforms. Store requirements, privacy declarations and purchases for games are in Mobile games. Keeping secrets out of app builds (SEC-11) and encrypting every connection (SEC-13) are in Security, third-party SDKs and personal data in Privacy and personal data, and sign-in in Authentication and sessions. Cross-platform apps are covered in React Native and Expo and Flutter.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

Apple publishes no single architecture guide for iOS apps. Use the framework documentation and the Swift guides below as the baseline, and the key rules for the decisions they leave open.

  • 9 OWASP Mobile Application Security Verification Standard (MASVS): the security requirements for mobile apps: storage, cryptography, authentication, network communication, platform interaction, code quality, resilience and privacy. The OWASP MASTG describes how to test each of them on iOS.
  • 8 SwiftUI (Apple Developer Documentation), with Model data and Managing model data in your app: the baseline for app structure, views and data flow: scenes, state, bindings, Observation and the environment.
  • 8 Concurrency (The Swift Programming Language): asynchronous functions, tasks and task groups, isolation, the main actor, actors and Sendable types. The Swift 6 concurrency migration guide explains data-race safety and how to adopt it in existing code.
  • 8 Swift API Design Guidelines (Swift.org): naming and API conventions, led by clarity at the point of use, that make your code read like the standard library.
  • 8 Human Interface Guidelines (Apple): the design guidance for Apple platforms. For architecture decisions, read Accessibility, which asks for larger text sizes, VoiceOver descriptions and support for other assistive technologies.
  • 7 Security (Apple Developer Documentation) and the Apple Platform Security guide: the Keychain, certificate, trust and cryptography APIs, and how the platform protects data on the device, including Data Protection classes.
  • 7 SwiftData (Apple Developer Documentation): persistence for Swift model classes, with schema versions and migrations, concurrency and syncing. The Backyard Birds sample app combines it with SwiftUI and Observation.
  • 7 Testing (Xcode): Swift Testing for unit tests, XCTest with XCUIAutomation for UI tests, test plans, code coverage and the test pyramid.

Key rules

State and data flow

  • 7 IOS-1 Make each shared model an @Observable class, create it with @State private var in the view or App that owns it, and pass it down as a plain property, with @Bindable where a subview needs bindings, or through .environment(_:). With Observation, available since iOS 17, a view updates only when a property that its body reads changes, and you use @State and @Environment instead of ObservableObject, @StateObject and @EnvironmentObject. (Apple, Managing model data in your app, Migrating from the Observable Object protocol to the Observable macro)
  • 7 IOS-2 Keep data and the logic that changes it in model types, not in views, and use @State only for state that a view owns: declare it private in the highest view that needs it, and pass the value or a binding to subviews. Separating the data model from the views makes the app more modular and easier to test. Don't do expensive work in a @State default value, which SwiftUI creates every time it creates the view; defer it to .task. (Apple, Managing model data in your app, State)

Concurrency

Secrets and secure connections

  • 9 IOS-6 Store tokens, passwords and keys in the Keychain with the most restrictive accessibility that works for the app, such as kSecAttrAccessibleWhenUnlockedThisDeviceOnly, not in UserDefaults, which stores data on disk unencrypted. Give files that hold personal data the complete Data Protection class if the app reads them only in the foreground. This is how iOS apps apply SEC-19. (Apple, UserDefaults, Restricting keychain item accessibility, Encrypting your app's files)
  • 9 IOS-7 Sign users in through ASWebAuthenticationSession, with the authorization code flow and PKCE (AUTH-2), never in a WKWebView. RFC 8252, the best current practice for OAuth in native apps, says that apps must not use embedded user agents for authorization requests. (IETF, RFC 8252, 8.12 Embedded user agents, Apple, ASWebAuthenticationSession)
  • 8 IOS-8 Keep App Transport Security on: don't set NSAllowsArbitraryLoads, fix a server that fails the ATS checks instead of adding an exception, and limit any exception you can't avoid to the domains that need it. This applies SEC-13. Exceptions reduce the app's security, and some must be justified in App Review. (Apple, Preventing insecure network connections)

Privacy

  • 9 IOS-9 Add a privacy manifest (PrivacyInfo.xcprivacy) to the app that declares the data it collects and an approved reason for each required reason API it uses, use the SDKs on Apple's list only in versions that include their privacy manifest (and their signature, if you add them as binaries), and compare the privacy report that Xcode generates from all the manifests with the App Store privacy details before each release. App Store Connect doesn't accept apps that use required reason APIs without a declared reason. This applies MOBGAME-6 and PRIV-11 to every app. (Apple, Privacy manifest files, Describing use of required reason API, Describing data use in privacy manifests, Third-party SDK requirements)

App lifecycle

  • 7 IOS-10 Save the user's work when the scene phase changes to .background, because the app may be terminated soon after, and restore lightweight UI state, such as the selected tab, with @SceneStorage. Keep model data and sensitive data out of @SceneStorage. (Apple, ScenePhase, SceneStorage)
  • 6 IOS-11 Do background work only through the system's mechanisms: finish a task the user started with beginBackgroundTask(withName:expirationHandler:), transfer large files with a background URLSession, and schedule refreshes and maintenance as BGAppRefreshTask and BGProcessingTask requests. The system decides when scheduled tasks run, and terminates the app if a task overruns its time. (Apple, Choosing background strategies for your app)

Persistence and networking

  • 7 IOS-12 Persist structured app data with SwiftData, or Core Data, and version the schema from the first release: describe each released schema with a VersionedSchema, and the migrations between them with a SchemaMigrationPlan. This applies DATA-2 to the data on users' devices; Core Data migrations likewise depend on properly versioned models. (Apple, SwiftData, VersionedSchema, SchemaMigrationPlan, Core Data, Staged migrations)
  • 6 IOS-13 Make HTTP requests with URLSession and its async methods, set waitsForConnectivity so that a request waits for a network instead of failing at once, and keep the data the user needs offline in local storage. Put timeouts and retries with backoff on every call (OPS-3). (Apple, TN3151: Choosing the right networking API, waitsForConnectivity, SwiftData)

Accessibility

  • 7 IOS-14 Use the built-in text styles, and make any custom font scale the same way, so that text follows Dynamic Type, give every meaningful image and custom control a VoiceOver label, and hide decorative images from VoiceOver. Check each screen with Accessibility Inspector, and in UI tests with performAccessibilityAudit(for:_:). This applies A11Y-9 and A11Y-12. (Apple, HIG: Typography, HIG: VoiceOver, Performing accessibility audits for your app)

Testing and delivery

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 7 Swift 6 language mode: set the Swift Language Version build setting (SWIFT_VERSION) to 6, or swift-tools-version: 6.0 in a package, and the compiler reports data-race safety violations as errors. In Swift 5 mode, Strict Concurrency Checking set to Complete reports them as warnings. Checks IOS-3.
  • 7 App Store Connect upload checks: App Store Connect doesn't accept builds that use required reason APIs without a declared reason, and rejects invalid privacy manifest files and listed SDKs without one. Uploading every build to TestFlight from CI runs these checks. Partly checks IOS-9.
  • 7 Accessibility audits in UI tests: performAccessibilityAudit(for:_:) fails a UI test when the current screen has issues such as missing element descriptions, insufficient contrast, clipped text or text that doesn't support Dynamic Type. Call it on every screen the tests visit. Partly checks IOS-14.
  • 6 Verifying the origin of your XCFrameworks (Xcode): the build fails if a binary SDK's code signature is removed, becomes invalid, or changes to a different developer. Partly checks IOS-9.
  • 6 Thread Sanitizer and Main Thread Checker (Xcode): turn them on for the Test action or in a test plan configuration. They report data races between threads, and system APIs called off the main thread, while the tests run. Partly checks IOS-3 and IOS-4.
  • 5 SwiftLint opt-in rules: private_swiftui_state flags @State properties that aren't private, and accessibility_label_for_image and accessibility_trait_for_button flag images without a label that aren't hidden from accessibility, and tappable views without a button or link trait. Partly checks IOS-2 and IOS-14.

Tutorials and further reading

  • 7 Develop in Swift Tutorials (Apple): building apps with Swift, SwiftUI, SwiftData and Swift Testing in Xcode, from the first project onwards.
  • 6 Embracing Swift concurrency (Apple, WWDC25): taking an app from single-threaded code to concurrency, and adding concurrency only where it's needed.
  • 6 Discover Observation in SwiftUI (Apple, WWDC23): how Observation tracks the properties a view reads, and how @State, @Environment and @Bindable work with it.
  • 6 Reducing your app's size (Apple): measuring download and install sizes with an app size report and App Store Connect, and optimizing assets and settings.