从Intel迁移至M1芯片后AppDelegate出现随机问题求助
M1 Mac + Xcode 15 迁移后模拟器异常解决指南
一、处理架构兼容警告
针对警告 Module "/usr/lib/system/libsystem_kernel.dylib" uses triple "arm64-apple-macosx13.6.0", which is not compatible with the target triple "arm64-apple-ios16.0.0-simulator",按以下步骤排查:
- 打开Xcode项目的Build Settings,找到
Excluded Architectures,在Debug模式下添加arm64(仅针对iOS Simulator); - 确认
Build Active Architecture Only在Debug模式下设置为Yes; - 清理项目缓存:点击Xcode顶部菜单
Product > Clean Build Folder,再手动删除~/Library/Developer/Xcode/DerivedData下对应项目的文件夹; - 检查所有Swift Package Manager依赖的包,确保它们支持arm64 iOS模拟器架构,旧依赖优先更新到最新版本。
二、解决NSConcreteTextStorage越界错误
错误 *** -[NSConcreteTextStorage attributesAtIndex:longestEffectiveRange:inRange:]: Range or index out of bounds 并非AppDelegate代码导致,而是页面文本控件的处理逻辑存在问题:
- 排查所有使用富文本(NSAttributedString)的UILabel、UITextView或UITextField,检查调用
attributesAtIndex:等方法时,传入的index是否超出文本长度; - 操作文本前先做判断:确保文本非空,且index在
0..<text.length有效范围内; - 若使用第三方文本相关库,更新到适配M1模拟器的最新版本。
三、解决UICollectionViewCell KVC未定义Key错误
错误 [<UICollectionViewCell 0x10b3b6e40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dayOfMonth 属于XIB/Storyboard绑定错误:
- 找到对应UICollectionViewCell的XIB或Storyboard文件,检查是否有控件绑定了
dayOfMonth这个key,但cell类中没有对应的@IBOutlet或@objc标记的属性; - 若不需要该绑定,直接在XIB/Storyboard中删除错误绑定;
- 若需要这个属性,在cell类中添加
@objc var dayOfMonth: UILabel!(或对应控件类型),并重新关联; - 确认cell的类名在XIB/Storyboard中已正确设置,未选错类。
附用户提供的AppDelegate代码:
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate { var window: UIWindow? let appId: String = "****" let region: String = "us" func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. let mySettings = AppSettings.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region: region).build() CometChat.init(appId: appId ,appSettings: mySettings,onSuccess: { (isSuccess) in if (isSuccess) { print("CometChat Pro SDK intialise successfully.") } }) { (error) in print("CometChat Pro SDK failed intialise with error: \(error.errorDescription)") } FirebaseApp.configure() GMSPlacesClient.provideAPIKey("****") UNUserNotificationCenter.current().delegate = self application.registerForRemoteNotifications() //UIApplication.shared.applicationIconBadgeNumber = 1 Messaging.messaging().delegate = self let config = CheckoutConfig( clientID: "****", environment: .live ) Checkout.set(config: config) return true } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { print("Cannot register for notifications: \(error)") } }
内容的提问来源于stack exchange,提问作者Senator
相关产品推荐
相关产品推荐

