跪拜 Guibai
← All articles
iOS

Xcode 26 Breaks AFNetworking Builds: Five Fixes, from Quick Patch to Full Migration

By 90后晨仔 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Thousands of legacy iOS apps still run on AFNetworking, and its 2023 archival means no official fix is coming. This single-line import error is a hard blocker for adopting Xcode 26, forcing teams to either automate a surgical fix or finally migrate to a maintained networking stack.

Summary

Upgrading to Xcode 26 causes AFNetworking to fail compilation with a 'netinet6/in6.h' file not found error. The archived library imports a private header that is now blocked by stricter module validation, even though the required IPv6 types are already available through a public header. Since the official repository no longer accepts contributions, developers must fix this themselves. A post-install Ruby script in the Podfile can automatically strip the offending import, while forking the repo and adding a Privacy Manifest offers a more controlled, long-term patch. For teams planning ahead, a full migration to Alamofire or native URLSession eliminates the dependency entirely. The core lesson is that technical debt in archived dependencies doesn't age out; it just waits for the next toolchain update to break the build.

Takeaways
Xcode 26 enforces Explicit Modules more strictly, prohibiting direct imports of Darwin private headers like <netinet6/in6.h>.
The required IPv6 type definitions are already provided by the public <netinet/in.h> header, making the AFNetworking import redundant.
A post_install script in the Podfile can automatically delete the offending import line from AFNetworking's source after every pod install.
Forking AFNetworking, applying the fix, and adding a Privacy Manifest creates a stable, reusable version for team use.
The cocoapods-patch plugin offers a lightweight alternative to a full fork by managing the one-line deletion as a patch file.
Disabling Explicit Modules in Build Settings is a temporary emergency workaround that masks the problem and increases compile times.
Migrating to Alamofire or a native URLSession wrapper removes the dependency on the archived library and aligns with modern Swift concurrency.
Conclusions

An archived library doesn't just stop improving; it becomes a time bomb where every OS or toolchain update can surface unfixed, legacy code patterns that were always technically incorrect.

The post_install script approach is effectively a community-driven, distributed maintenance model: the fix lives in project Podfiles rather than in a central repository.

Apple's push for Explicit Modules and Privacy Manifests is quietly forcing a long-overdue cleanup of the Objective-C dependency ecosystem, whether library authors participate or not.

Concepts & terms
Explicit Modules
A Clang compiler mode, now default in Xcode 26, that builds modules upfront and strictly validates imports. It prevents source files from directly including private or non-modular headers, improving build performance and hygiene.
Privacy Manifest (PrivacyInfo.xcprivacy)
A required plist file for iOS SDKs that declares data collection practices and accessed privacy-sensitive APIs. Apple mandates it for third-party SDKs to improve transparency and app-store compliance.
From the discussion
Featured comments
向新出发叭

Very thorough compilation, the scenario breakdown for the five solutions is clear. We've also used post_install to batch-process other legacy issues in Pods before; it's idempotent and works in CI, making it the top choice for team scenarios. Two additions: first, when forking for solution two, it's crucial to put the repo under the team organization and note the corresponding upstream commit in the README—this saves a lot of backtracking effort during future upgrades, and it's great that the article mentioned this. Second, we used solution four once in an emergency; the compilation time did increase and we lost module validation, so we switched back to solution one right after shipping the build. Solution five's migration is a permanent fix, but the regression testing cost for legacy projects is significant. Our approach is to first fix the build with solution one or three, then schedule the migration as technical debt to be digested gradually. Thanks for sharing, bookmarked!

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗