Closed leandromperez closed 6 years ago
Do you have any optimisations in build settings? If you have any IUO properties in the registered types try to turn them to Optionals and see if crash still happens.
I have no optimizations. I don't have any IUO in the objects being resolved. I do have IUO in other dependencies, but none in those 3 objects.
Can you try turning your lazy properties in CoreDataService to optionals and initialise them in init and see if it helps? I think it might cause issues as we try to access those properties for the first time through Mirror.
I removed all the other app dependencies and left only the CoreDataService. I removed the lazy properties and it worked again. As you thought, that is the issue. Any ideas on why it only happens in the device?
Don't know to be honest, but there were some issues regarding mirroring types with IUO properties (and lazy is still optional, so it might be related). Maybe it is also affected by the fact that it is CoreData types... Will try to reproduce that on a weekend and probably file a bug for Swift, or I will try to come up with some fix to avoid accessing lazy properties while doing auto-injection, as we already do for IUO properties, probably simply by ignoring any property with optional type. At least now you know what is the issue and I hope not using lazy properties, if any hotfix will not work, will not be a a big issue for you.
Btw you might also try to turn your lazy properties to IUO, that might help as we skip accessing them during auto-injection, so it might work for you without any other fixes on our side
Thanks for everything @ilyapuchka. Removing the lazy properties fixed the problem. I added some code and created a pull request so you can reproduce the crash if you want to.
Hi @ilyapuchka I am attaching the stack trace for the crashing thread.
This is the log: Resolving type DataInitializer with arguments () Resolving type Database with arguments () while injecting in type DataInitializer Resolving type CoreDataService with arguments () while injecting in type Database
AppDelegate.swift.txt AppDependencies.swift.txt CoreDataService copy.swift.txt
StackTrace Thread 1.txt
I am still trying to find the issue.
Thanks!