Le code de données de base par défaut renvoie une erreur pour une raison quelconque. Cela a juste commencé à se produire après que j'ai essayé de migrer vers une nouvelle version du modèle de données, donc je suis sûr que j'ai fait quelque chose pour bousiller ça. Voici le code correspondant:Données de base: bundle.main.url renvoyant NIL de manière inattendue (et soudainement)
enter colazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
let modelURL = Bundle.main.url(forResource: "Band_Manager_2_0", withExtension: "momd")!
return NSManagedObjectModel(contentsOf: modelURL)!
}()
La ligne de lancer l'erreur est celle-ci:
enter let modelURL = Bundle.main.url(forResource: "Band_Manager_2_0", withExtension: "momd")!code here
Et voici l'erreur:
fatal error: unexpectedly found nil while unwrapping an Optional value
2017-04-21 14:17:01.620046-0400 Band Manager 2.0[5826:164435] fatal error: unexpectedly found nil while unwrapping an Optional value
Current stack trace:
0 libswiftCore.dylib 0x0000000100425160 swift_reportError + 129
1 libswiftCore.dylib 0x0000000100441b80 _swift_stdlib_reportFatalError + 60
2 libswiftCore.dylib 0x0000000100231a00 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
3 libswiftCore.dylib 0x00000001003acec0 partial apply for (_fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never).(closure #2) + 109
4 libswiftCore.dylib 0x0000000100231a00 specialized specialized StaticString.withUTF8Buffer<A> ((UnsafeBufferPointer<UInt8>) -> A) -> A + 342
5 libswiftCore.dylib 0x000000010035f4a0 specialized _fatalErrorMessage(StaticString, StaticString, file : StaticString, line : UInt, flags : UInt32) -> Never + 96
6 Band Manager 2.0 0x000000010005f500 AppDelegate.(managedObjectModel.getter).(closure #1) + 463
7 Band Manager 2.0 0x000000010005d8d0 AppDelegate.managedObjectModel.getter + 194
8 Band Manager 2.0 0x000000010005f880 AppDelegate.(persistentStoreCoordinator.getter).(closure #1) + 1115
9 Band Manager 2.0 0x000000010005dad0 AppDelegate.persistentStoreCoordinator.getter + 211
10 Band Manager 2.0 0x0000000100061020 AppDelegate.(managedObjectContext.getter).(closure #1) + 35
11 Band Manager 2.0 0x000000010005dce0 AppDelegate.managedObjectContext.getter + 211
12 Band Manager 2.0 0x000000010005a0d0 AppDelegate.applicationDidFinishLaunching(Notification) ->() + 51
13 Band Manager 2.0 0x000000010005d530 @objc AppDelegate.applicationDidFinishLaunching(Notification) ->() + 71
14 CoreFoundation 0x00007fff85d1c520 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
15 CoreFoundation 0x00007fff85d1c280 _CFXRegistrationPost + 427
16 CoreFoundation 0x00007fff85d1c160 ___CFXNotificationPost_block_invoke + 50
17 CoreFoundation 0x00007fff85cd9f90 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018
18 CoreFoundation 0x00007fff85cd94c0 _CFXNotificationPost + 667
19 Foundation 0x00007fff8771a955 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
20 AppKit 0x00007fff839439f6 -[NSApplication _postDidFinishNotification] + 297
21 AppKit 0x00007fff839437b4 -[NSApplication _sendFinishLaunchingNotification] + 208
22 AppKit 0x00007fff838069c1 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 552
23 AppKit 0x00007fff838065a6 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 661
24 Foundation 0x00007fff87765cfb -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 290
25 Foundation 0x00007fff87765c31 _NSAppleEventManagerGenericHandler + 102
26 AE 0x00007fff86b6ad06 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned int, unsigned char*) + 544
27 AE 0x00007fff86b6ac76 dispatchEventAndSendReply(AEDesc const*, AEDesc*) + 39
28 AE 0x00007fff86b6aa71 aeProcessAppleEvent + 312
29 HIToolbox 0x00007fff85277da8 AEProcessAppleEvent + 55
30 AppKit 0x00007fff838019c4 _DPSNextEvent + 1833
31 AppKit 0x00007fff83f7cd72 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 2796
32 AppKit 0x00007fff837f640d -[NSApplication run] + 926
33 AppKit 0x00007fff837c0d09 NSApplicationMain + 1237
34 Band Manager 2.0 0x00000001000613d0 main + 13
35 libdyld.dylib 0x00007fff9b8ad234 start + 1
(lldb)
J'espère que quelqu'un aura un aperçu quant à la façon de résoudre ce problème. Je suis relativement nouveau pour les données de base et mon codage est complètement arrêté, car l'application se bloque immédiatement après le lancement.
Merci! MISE À JOUR: Je devrais clarifier, que je comprends la raison technique pour laquelle cela se produit (ne pas trouver une ressource nécessaire) mais je n'ai aucune idée comment résoudre ce problème. La ressource qu'elle ne semble pas trouver est quelque chose qui a été générée automatiquement à un moment donné dans le passé. Je n'arrive pas à comprendre comment obtenir XCODE pour régénérer le fichier nécessaire, ou même pourquoi il a disparu en premier lieu.
Si 'url (forResource' renvoie' nil' alors la ressource est manquante – vadian
Ce que j'obtiens ... la question est ... où cette ressource devrait-elle être, et comment puis-je la remplacer? Quelque chose a été généré automatiquement, parce que je ne l'ai pas créé manuellement, puisque je suis toujours en développement, je suis content de jeter toutes mes données de test et j'ai juste XCODE recréer un fichier de données vide pour le faire fonctionner à nouveau, mais n'ont pas été en mesure de comprendre comment faire cela. –