Xcode9.3.1+Swift4.1下CryptoSwift报‘GCM未解析标识符’错误求助
Hey there, let's work through this issue you're facing with CryptoSwift's GCM mode. Since your basic AES functions are working, the problem is likely tied to how the GCM component is being exposed or loaded in your specific environment. Here are the most targeted fixes to try:
1. Verify CryptoSwift Master Branch Compatibility with Swift 4.1
While you installed the latest master branch, newer commits in CryptoSwift may have dropped official support for older Swift versions like 4.1. To address this:
- Pin CryptoSwift to a specific commit confirmed to work with Swift 4.1 (look for commits from 2019 or earlier that explicitly mention GCM support). Update your Podfile like this:
pod 'CryptoSwift', :git => 'https://github.com/krzyzanowskim/CryptoSwift.git', :commit => 'INSERT_COMPATIBLE_COMMIT_HASH_HERE' - Run
pod update CryptoSwiftto install this compatible version.
2. Clear Xcode's Derived Data and Rebuild
Xcode's cached build data often causes weird identifier resolution glitches. Follow these steps:
- Quit Xcode entirely.
- Open Finder, press
Cmd + Shift + G, and paste~/Library/Developer/Xcode/DerivedData - Delete the folder linked to your project.
- Reopen Xcode, clean the project with
Cmd + Shift + K, then rebuild withCmd + B.
3. Check for GCM Class Naming Changes
In older CryptoSwift versions, GCM wasn't always a top-level class. Try modifying your code to use the nested AES.GCM structure instead:
do { let gcm = AES.GCM(iv: iv, mode: .combined) let aes = try AES(key: key, blockMode: gcm, padding: .noPadding) let encrypted = try aes.encrypt(plaintext) let tag = gcm.authenticationTag } catch { // Handle error }
This is a common naming pattern in older releases that might resolve the "unresolved identifier" error.
4. Reinstall CocoaPods Dependencies
Corrupted Pod installations can cause missing components. Do a fresh install:
- Run
pod deintegrateto remove all existing Pods from your project. - Delete the
Podfile.lockfile andPodsfolder. - Run
pod repo updateto fetch the latest repo info. - Run
pod installto reinstall all dependencies, including CryptoSwift.
内容的提问来源于stack exchange,提问作者Yongxian Tan

