我只在所有iPhone 5设备上收到上述错误.不知道这里发生了什么,但也许这个5位是32位设备的事实可能是一个线索?
我从vIEwcontroller类调用以下方法
func startRecording() { disableControls() CoreDataStack.shared.performForegroundTask { (context) in let sessionInfo = SessionInfo(context: context) sessionInfo.startTime = Date().timeIntervalSince1970 sessionInfo.userID = self.config.userID sessionInfo.deviceposition = self.config.deviceposition.rawValue sessionInfo.deviceType = self.config.deviceType.rawValue sessionInfo.deviceNumber = self.config.deviceNumber sessionInfo.deviceSIDe = self.config.deviceSIDe.rawValue do { try context.obtainPermanentIDs(for: [sessionInfo]) } catch { print("Error obtaining permanent ID for session info record") return } CoreDataStack.shared.saveVIEwContextAnDWait() dispatchQueue.main.async { guard sessionInfo.objectID.istemporaryID == false else { print("ObjectID is temporary") return } self.recording = true self.statusLabel.text = "Recording..." self.recordManager.start(sessionUID: sessionInfo.uID) } }}
config变量是一个简单的结构:
struct Configuration { var userID: String = "UnkNown" var deviceType: DeviceType = .phone // enum: String var deviceSIDe: DeviceSIDe = .notApplicable // enum: String var deviceNumber: Int16 = 1 var deviceposition: Deviceposition = .waist // enum: String}
CoreDataStack在这里:
final class CoreDataStack { static let shared = CoreDataStack() private init() {} var errorHandler: (Error) -> VoID = { error in log.error("\(error),\(error._userInfo)") } private struct constants { static let persistentStorename = "Model" } private lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: constants.persistentStorename) container.loadPersistentStores(completionHandler: { [weak self] (storeDescription,error) in if let error = error { self?.errorHandler(error) } }) return container }() lazy var vIEwContext: NSManagedobjectContext = { self.persistentContainer.vIEwContext.mergePolicy = NSMergePolicy.mergeByPropertyObjectTrump self.persistentContainer.vIEwContext.automaticallyMergesChangesFromParent = true try! self.persistentContainer.vIEwContext.setqueryGenerationFrom(.current) return self.persistentContainer.vIEwContext }() private lazy var backgroundContext: NSManagedobjectContext = { let context = self.persistentContainer.newBackgroundContext() context.mergePolicy = NSMergePolicy.mergeByPropertyStoreTrump return context }() func performForegroundTask(_ block: @escaPing (NSManagedobjectContext) -> VoID) { self.vIEwContext.performAnDWait { block(self.vIEwContext) } } func performBackgroundTask(_ block: @escaPing (NSManagedobjectContext) -> VoID) { backgroundContext.perform { block(self.backgroundContext) } } func saveBackgroundContext() { vIEwContext.performAnDWait { do { if self.vIEwContext.hasChanges { try self.vIEwContext.save() } } catch { self.errorHandler(error) } self.backgroundContext.perform { do { if self.backgroundContext.hasChanges { try self.backgroundContext.save() self.backgroundContext.refreshAllObjects() } } catch { self.errorHandler(error) } } } } func saveVIEwContext() { vIEwContext.perform { if self.vIEwContext.hasChanges { do { try self.vIEwContext.save() } catch { self.errorHandler(error) } } } } func saveVIEwContextAnDWait() { vIEwContext.performAnDWait { if self.vIEwContext.hasChanges { do { try self.vIEwContext.save() } catch { self.errorHandler(error) } } } }}
代码在startRecording方法的下一行轰炸:
try context.obtainPermanentIDs(for: [sessionInfo])
编辑:
我创建了一个精简测试应用程序,它只包含CoreDataStack和一个带有一个属性类型为string的实体的模型.我仍然只在3x iPhone 5上出现同样的错误. 5s,6s,7都可以正常工作.
这可能意味着问题在于CoreDataStack吗?
Github回购here
解决方法 有几个人问我是否解决了这个问题,所以这就是我所做的.这不是一个真正的解决方案,而是更多的解决方法.它可能不适合所有人,但为我工作.我所做的只是删除线
try! self.persistentContainer.vIEwContext.setqueryGenerationFrom(.current)
来自CoreDataStack,问题消失了……
总结以上是内存溢出为你收集整理的ios – EXC_BAD_ACCESS代码= EXC_ARM_DA_ALIGN全部内容,希望文章能够帮你解决ios – EXC_BAD_ACCESS代码= EXC_ARM_DA_ALIGN所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)