Swit 5.1 Adding CoreData to an Existing project But I got this error - swift5

2020-04-05 16:18:10.014238+0530 StayHome[2732:178019] [error] error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'NotifyDetails' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
CoreData: error: No NSEntityDescriptions in any model claim the NSManagedObject subclass 'NotifyDetails' so +entity is confused. Have you loaded your NSManagedObjectModel yet ?
2020-04-05 16:18:10.014435+0530 StayHome[2732:178019] [error] error: +[NotifyDetails entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
CoreData: error: +[NotifyDetails entity] Failed to find a unique match for an NSEntityDescription to a managed object subclass
2020-04-05 16:18:10.016103+0530 StayHome[2732:178019] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'An NSManagedObject of class 'NotifyDetails' must have a valid NSEntityDescription.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110cb527e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x000000010c3e5b20 objc_exception_throw + 48
2 CoreData 0x000000010c939d28 -[NSManagedObject initWithEntity:insertIntoManagedObjectContext:] + 485
3 StayHome 0x000000010b94470f $s8StayHome13NotifyDetailsC6entity10insertIntoACSo19NSEntityDescriptionC_So22NSManagedObjectContextCSgtcfc + 111
4 StayHome 0x000000010b9447fc $s8StayHome13NotifyDetailsC6entity10insertIntoACSo19NSEntityDescriptionC_So22NSManagedObjectContextCSgtcfcTo + 76
5 CoreData 0x000000010c9e767e -[NSManagedObject initWithContext:] + 290
6 StayHome 0x000000010b90484f $sSo15NSManagedObjectC7contextABSo0aB7ContextC_tcfcTO + 31
7 StayHome 0x000000010b9042b7 $sSo15NSManagedObjectC7contextABSo0aB7ContextC_tcfC + 39
8 StayHome 0x000000010b903f7a $s8StayHome13LocalDatabaseV0C4DatayySS_SStF + 282
9 StayHome 0x000000010b9079ef $s8StayHome17LocalNotificationC0D0yySS_SStFySb_s5Error_pSgtcfU_ + 223
10 StayHome 0x000000010b907f6f $sSbs5Error_pSgIegyg_SbSo7NSErrorCSgIeyByy_TR + 127
11 libdispatch.dylib 0x0000000111afedd4 _dispatch_call_block_and_release + 12
12 libdispatch.dylib 0x0000000111affd48 _dispatch_client_callout + 8
13 libdispatch.dylib 0x0000000111b065ef _dispatch_lane_serial_drain + 788
14 libdispatch.dylib 0x0000000111b071b5 _dispatch_lane_invoke + 476
15 libdispatch.dylib 0x0000000111b12a4e _dispatch_workloop_worker_thread + 719
16 libsystem_pthread.dylib 0x0000000111f7c6fc _pthread_wqthread + 290
17 libsystem_pthread.dylib 0x0000000111f7b827 start_wqthread + 15
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

I've had the same issue and tried several solutions like commenting out
#objc(CheatTime)
or selecting Current product module in .xcdatamodeld
Nothing worked.
After that I tried to make a fetch request before adding a new object and it worked
So in my cases I've added following code:
let request = CheatTime.fetchRequest() as NSFetchRequest<CheatTime>
request.sortDescriptors = [NSSortDescriptor(key: #keyPath(CheatTime.numberOfHours), ascending: true)]
let fetchedRC = NSFetchedResultsController(fetchRequest: request, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
try? fetchedRC.performFetch()
After that objects were added without a problem, not only for the first object type (CheatTime in my example), but for the second one too (without additional fetch request)

Related

How to solve NSInternalInconsistencyException: reason: 'Invalid parameter not satisfying: (name != nil) && ([name length] > 0)'

I get an NSInternalInconsistencyException when I use the OPPWAMobile payment library. I need to pass name somehow to OPPPaymentSchemeViewController so it passes it to initWithNibName. But I'm not sure how to do that in Xcode.
I've checked this stack overflow solution but it didn't help because I don't have direct access to the view controller.
I'm sure that the nib name is part of a property file somewhere but I'm not able to locate it.
Any ideas on how to do that?
2021-06-22 08:24:27.468604+0300 Runner[6738:85985] *** Assertion failure in -[UINib initWithNibName:directory:bundle:], UINib.m:97
2021-06-22 08:25:12.078452+0300 Runner[6738:85985] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: (name != nil) && ([name length] > 0)'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff20422fba __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20193ff5 objc_exception_throw + 48
2 CoreFoundation 0x00007fff20422de3 +[NSException raise:format:] + 0
3 Foundation 0x00007fff207748e7 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x00007fff242b63de -[UINib initWithNibName:directory:bundle:] + 309
5 UIKitCore 0x00007fff242b6489 +[UINib nibWithNibName:bundle:] + 76
6 OPPWAMobile 0x00000001067e9736 -[OPPPaymentSchemeViewController registerTableViewCellNibs] + 153
7 OPPWAMobile 0x00000001067e9389 -[OPPPaymentSchemeViewController viewDidLoad] + 157
8 UIKitCore 0x00007fff23f806a9 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 88
9 UIKitCore 0x00007fff23f8504c -[UIViewController loadViewIfRequired] + 1084
10 UIKitCore 0x00007fff23f85436 -[UIViewController view] + 27
11 UIKitCore 0x00007fff23ec6559 -[UINavigationController _preferredContentSizeForcingLoad:] + 198
12 UIKitCore 0x00007fff23e64354 -[UIPresentationController preferredContentSizeDidChangeForChildContentContainer:] + 64
13 UIKitCore 0x00007fff23e6018f __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.466 + 178
14 UIKitCore 0x00007fff24bb1e36 -[_UIAfterCACommitBlock run] + 54
15 UIKitCore 0x00007fff246d01f8 _runAfterCACommitDeferredBlocks + 333
16 UIKitCore 0x00007fff246c01e4 _cleanUpAfterCAFlushAndRunDeferredBlocks + 221
17 UIKitCore 0x00007fff246f1a36 _afterCACommitHandler + 85
18 CoreFoundation 0x00007fff2038fd31 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
19 CoreFoundation 0x00007fff2038a542 __CFRunLoopDoObservers + 541
20 CoreFoundation 0x00007fff2038aaf5 __CFRunLoopRun + 1129
21 CoreFoundation 0x00007fff2038a1a7 CFRunLoopRunSpecific + 567
22 GraphicsServices 0x00007fff2b874d85 GSEventRunModal + 139
23 UIKitCore 0x00007fff246c14df -[UIApplication _run] + 912
24 UIKitCore 0x00007fff246c639c UIApplicationMain + 101
25 Runner 0x00000001064fec8b main + 75
26 libdyld.dylib 0x00007fff2025abbd start + 1
)
libc++abi: terminating with uncaught exception of2021-06-22 08:25:12.691736+0300 Runner[6738:88777] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed
type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: (name != nil) && ([name length] > 0)'
terminating with uncaught exception of type NSException
I found the problem. I needed to mark OPPWAMobile.xcframework as "Embed & Sign" under Target->General->Frameworks, Libraries and Embedded Content.
I suspected that this may be the problem when I read the Apple documentation on how initWithNibName:bundle: behaves when nibName is nil.
If you specify nil for the nibName parameter and you do not override
the loadView method, the view controller searches for a nib file as
described in the nibName property.
Which means that I was getting an exception because the framework couldn't find the necessary nib file.
You have add OPPWAMobile-Resources.bundle on project.

UITableView unable to dequeue a cell with identifier [duplicate]

This question already has answers here:
Swift 'unable to dequeue a cell with identifier intervalCellIdentifier
(3 answers)
Closed 2 years ago.
I get this issue when i run my xcode Project. i will start the project and the simulator will load but as soon as it loads up the app i am making it crashes.
This is the error code :Thread 1: Exception: "unable to dequeue a cell with identifier ChecklistItem - must register a nib or a class for the identifier or connect a prototype cell in a storyboard"
and says this in the terminal:
2020-07-24 18:11:06.757164+0100 Checklists[983:49709] *** Assertion failure in -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:], /Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3920.31.102/UITableView.m:8724
2020-07-24 18:11:06.771044+0100 Checklists[983:49709] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier ChecklistItem - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b93ae6e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x000000010a23a9b2 objc_exception_throw + 48
2 CoreFoundation 0x000000010b93abe8 +[NSException raise:format:arguments:] + 88
3 Foundation 0x0000000109c1bbd2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
4 UIKitCore 0x000000010e53d6be -[UITableView _dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:] + 1332
5 UIKitCore 0x000000010e53d156 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 91
6 Checklists 0x0000000109979a38 $s10Checklists23ChecklistViewControllerC05tableC0_12cellForRowAtSo07UITableC4CellCSo0jC0C_10Foundation9IndexPathVtF + 264
7 Checklists 0x0000000109979b25 $s10Checklists23ChecklistViewControllerC05tableC0_12cellForRowAtSo07UITableC4CellCSo0jC0C_10Foundation9IndexPathVtFTo + 165
8 UIKitCore 0x000000010e556e96 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 867
9 UIKitCore 0x000000010e520522 -[UITableView _updateVisibleCellsNow:] + 3010
10 UIKitCore 0x000000010e54024e -[UITableView layoutSubviews] + 194
11 UIKitCore 0x000000010e8465f4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
12 QuartzCore 0x00000001103b1260 -[CALayer layoutSublayers] + 255
13 QuartzCore 0x00000001103b73eb _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 523
14 QuartzCore 0x00000001103c2a8a _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
15 QuartzCore 0x000000011030ba7c _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
16 QuartzCore 0x000000011033f467 _ZN2CA11Transaction6commitEv + 649
17 UIKitCore 0x000000010e3566c3 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
18 CoreFoundation 0x000000010b89eabc __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
19 CoreFoundation 0x000000010b89e1b3 __CFRunLoopDoBlocks + 195
20 CoreFoundation 0x000000010b898fa3 __CFRunLoopRun + 995
21 CoreFoundation 0x000000010b8988a4 CFRunLoopRunSpecific + 404
22 GraphicsServices 0x0000000114910bbe GSEventRunModal + 139
23 UIKitCore 0x000000010e33e968 UIApplicationMain + 1605
24 Checklists 0x000000010997aa1b main + 75
25 libdyld.dylib 0x000000010c8581fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Based on the error, you did not register the cell when setting up the tableview.
Check the documentation:
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "DefaultCell")
Or
tableView.register(UINib(nibName: "yourNib", bundle: nil), forCellReuseIdentifier: "CellFromNib")
Just fill in the proper values for cell, nibName, identifier, etc... Depending on which method you're using
And here is a link to a guide if you need a bit more info: link

Quick nimble variable is always nil

I create a basic test case, I cannot instantiate the variable. And while test is running, it always crashes.
import Foundation
import XCTest
import Quick
import Nimble
import UIKit
#testable import tar22102
class ViewControllerTests: QuickSpec {
override func spec() {
var vc: ViewController?
beforeEach{               
vc = ViewController()
let _ = vc?.view
}
describe("testing Initial values") {
context("Reading values") {
expect(vc).toNot(beNil())
}
}
}
This is the crash log. I put breakpoint to the lines in the beforeEach, it would not reach. I also have switched to several different projects. The same issue happens.
2020-07-18 07:49:36.935064-0400 tar22102[15304:300447] Launching with XCTest injected. Preparing to run tests.
2020-07-18 07:49:37.263912-0400 tar22102[15304:300447] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An exception occurred when building Quick's example groups.
Some possible reasons this might happen include:
- An 'expect(...).to' expectation was evaluated outside of an 'it', 'context', or 'describe' block
- 'sharedExamples' was called twice with the same name
- 'itBehavesLike' was called with a name that is not registered as a shared example
Here's the original exception: 'NSInternalInconsistencyException', reason: 'Attempted to report a test failure to XCTest while no test case was running. The failure was:
"expected to not be nil, got <nil>
"
It occurred at: /Users/hzhan25/Desktop/DD/22102/22102Tests/_2102Tests.swift:27', userInfo: '(null)''
*** First throw call stack:
(
0 CoreFoundation 0x000000010eb8327e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x000000010ce4db20 objc_exception_throw + 48
2 CoreFoundation 0x000000010eb830bc +[NSException raise:format:] + 188
3 22102Tests 0x000000012b7dc8f9 __23+[QuickSpec initialize]_block_invoke + 457
4 22102Tests 0x000000012b7f8cda $sIyB_Ieg_TR + 10
5 22102Tests 0x000000012b7f8b82 $s5Quick5WorldC30performWithCurrentExampleGroup_7closureyAA0fG0C_yyXEtF + 370
6 22102Tests 0x000000012b7f8c9b $s5Quick5WorldC30performWithCurrentExampleGroup_7closureyAA0fG0C_yyXEtFTo + 107
7 22102Tests 0x000000012b7dc705 +[QuickSpec initialize] + 229
8 libobjc.A.dylib 0x000000010ce4e103 CALLING_SOME_+initialize_METHOD + 17
9 libobjc.A.dylib 0x000000010ce4eee9 initializeNonMetaClass + 624
10 libobjc.A.dylib 0x000000010ce4f4ba _ZL24initializeAndMaybeRelockP10objc_classP11objc_objectR8mutex_ttILb0EEb + 157
11 libobjc.A.dylib 0x000000010ce59a5d lookUpImpOrForward + 595
12 libobjc.A.dylib 0x000000010ce4a219 _objc_msgSend_uncached + 73
13 Foundation 0x000000010d12852b -[NSBundle loadAndReturnError:] + 1141
14 libXCTestBundleInject.dylib 0x000000010cc46719 __XCTestBundleInject + 538
15 ??? 0x000000010cbb53a7 0x0 + 4508570535
16 ??? 0x000000010cbb57b8 0x0 + 4508571576
17 ??? 0x000000010cbb09a2 0x0 + 4508551586
18 ??? 0x000000010cbaf7a6 0x0 + 4508546982
19 ??? 0x000000010cbaf846 0x0 + 4508547142
20 ??? 0x000000010cba4046 0x0 + 4508500038
21 ??? 0x000000010cba80fc 0x0 + 4508516604
22 ??? 0x000000010cba31cd 0x0 + 4508496333
23 ??? 0x000000010d055234 0x0 + 4513419828
24 ??? 0x000000010d0530ce 0x0 + 4513411278
25 ??? 0x000000010d04e503 0x0 + 4513391875
26 ??? 0x000000010d04e036 0x0 + 4513390646
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Matcher calls need to be inside an it block
describe("Initial values") {
it("Sets vc") {
expect(vc).toNot(beNil())
}
}

iOS crash 'NSInternalInconsistencyException', reason: 'statement is still active' Core Data cache related?

Very occasionally seeing these pop up in crash reports on screens using NSFetchedResultsController, and not sure how to address them. I don't believe I'm using threading anywhere, unless NSFetchedResults is using them internally.
'NSInternalInconsistencyException', reason: 'statement is still active' is the full explanation I get.
Two recent stack traces:
0 CoreFoundation 0x37a368bf __exceptionPreprocess + 163
1 libobjc.A.dylib 0x3151c1e5 objc_exception_throw + 33
2 CoreData 0x340b2ea5 -[NSSQLiteStatement cachedSQLiteStatement] + 1
3 CoreData 0x340b274f -[NSSQLiteConnection prepareSQLStatement:] + 55
4 CoreData 0x34156049 -[NSSQLChannel selectRowsWithCachedStatement:] + 61
5 CoreData 0x34181d63 newFetchedRowsForFetchPlan_MT + 783
6 CoreData 0x340bab07 -[NSSQLCore newRowsForFetchPlan:] + 351
7 CoreData 0x34160011 -[NSSQLCore fetchRowForObjectID:] + 1005
8 CoreData 0x340cca57 -[NSSQLCore newValuesForObjectWithID:withContext:error:] + 195
9 CoreData 0x340cbf83 _PFFaultHandlerLookupRow + 423
10 CoreData 0x340cba97 _PF_FulfillDeferredFault + 187
11 CoreData 0x340cb94f _sharedIMPL_pvfk_core + 39
12 PowerPro 0x0006a779 -[GuestCard getPrimaryProspectiveTenant] (GuestCard.m:77)
13 PowerPro 0x00017bf9 -[OutstandingFollowupsViewController configureCell:atIndexPath:] (OutstandingFollowupsViewController.m:208)
14 PowerPro 0x00017b9b -[OutstandingFollowupsViewController tableView:cellForRowAtIndexPath:] (OutstandingFollowupsViewController.m:203)
Last Exception Backtrace:
0 CoreFoundation 0x37a368bf __exceptionPreprocess + 163
1 libobjc.A.dylib 0x3151c1e5 objc_exception_throw + 33
2 CoreData 0x340b2ea5 -[NSSQLiteStatement cachedSQLiteStatement] + 1
3 CoreData 0x340b274f -[NSSQLiteConnection prepareSQLStatement:] + 55
4 CoreData 0x34156049 -[NSSQLChannel selectRowsWithCachedStatement:] + 61
5 CoreData 0x340c26eb -[NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument:] + 515
6 CoreData 0x340bab3f -[NSSQLCore newRowsForFetchPlan:] + 407
7 CoreData 0x3415ea55 -[NSSQLCore newFetchedPKsForSourceID:andRelationship:] + 2217
8 CoreData 0x3416a935 -[NSSQLCore newValueForRelationship:forObjectWithID:withContext:error:] + 689
9 CoreData 0x34108f8b -[NSFaultHandler retainedFulfillAggregateFaultForObject:andRelationship:withContext:] + 479
10 CoreData 0x340dcb23 -[_NSFaultingMutableSet willRead] + 219
11 CoreData 0x340dc70b -[_NSFaultingMutableSet count] + 23
12 PowerPro 0x00016eb1 -[BrowseGuestCardsViewController configureCell:atIndexPath:] (BrowseGuestCardsViewController.m:246)
13 PowerPro 0x00017173 -[BrowseGuestCardsViewController tableView:cellForRowAtIndexPath:] (BrowseGuestCardsViewController.m:222)
14 UIKit 0x34e4e9cb -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 547
15 UIKit 0x34e4daa9 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1077
16 UIKit 0x34e4d233 -[UITableView layoutSubviews] + 207
17 UIKit 0x34df1d4b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 183
18 CoreFoundation 0x3799522b -[NSObject performSelector:withObject:] + 43
19 QuartzCore 0x3318c381 -[CALayer layoutSublayers] + 217
20 QuartzCore 0x3318bf99 CA::Layer::layout_if_needed(CA::Transaction*) + 217
21 QuartzCore 0x3318bea5 -[CALayer layoutIfNeeded] + 153
22 UIKit 0x34eb6fe1 -[UIButton titleLabel] + 73
23 PowerPro 0x00017983 -[BrowseGuestCardsViewController viewDidLoad] (BrowseGuestCardsViewController.m:75)
It's more than likely that this is a threading problem in some way or another. There isn't quite enough information in the question to see for sure, but it's worth check through the crash logs and looking at the stack traces for all threads at the time of the exception, and see if any other threads are doing anything which interacts with a managed object. It could be that you have a notification handler, a URL connection completion handler, or some other bit of code using concurrency which you hadn't noticed, using core data objects in the background. It's worth noting that setting or accessing any property on any managed object from a context that's being used on more than one thread could potentially trigger this kind of exception, which can make it pretty tough to diagnose.
The relatively simple solution to solving these problems in most apps is to push the execution of that code to the main thread (using dispatch_async()). Alternatively, if you've got lots of processing to do it might be better to create a child context on the background thread and re-fetch the object from the child context, then save the child context. Of course, to re-fetch the object you need to have its objectID, which is a property which can only be accessed on the thread the object was originally fetched on…
Got this error while simultaneously requesting data with NSFetchedResultController (from main thread context) and NSFetchRequest through my background context.
The way I have handled this is by making each of my MOCs have its own persistent store coordinator. Both of the persistent store coordinators talk to the same persistent store on disk.

App terminate due to - uncaught exception 'NSGenericException',

I got the below error while fetching some data from sever. While fetching data, i m displaying an custom alert view with activity indicator. Alert is using main thread while data fetching is done by NSThread. This problem occurs only at some time, not always. I m not able to understand what to do.
* Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection was mutated while being enumerated.(
"",
"",
""
)'
* Call stack at first throw:
(
0 CoreFoundation 0x00f2abe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0107f5c2 objc_exception_throw + 47
2 CoreFoundation 0x00f2a6a9 __NSFastEnumerationMutationHandler + 377
3 UIKit 0x00371b8e -[UIView(Hierarchy) _findFirstSubviewWantingToBecomeFirstResponder] + 189
4 UIKit 0x00366a13 -[UIView(Hierarchy) _promoteDescendantToFirstResponderIfNecessary] + 42
5 MyApplnName 0x00015154 -[SecondViewController getDataFromServer] + 1798
6 Foundation 0x000a1d4c -[NSThread main] + 81
7 Foundation 0x000a1cd8 __NSThread__main__ + 1387
8 libSystem.B.dylib 0x928db7fd _pthread_start + 345
9 libSystem.B.dylib 0x928db682 thread_start + 34
)
terminate called after throwing an instance of 'NSException'
The problem is in part of your code where you enumerate some object, for example, NSMutableArray or NSMutableSet, using for-loop (for (id _obj in object)) and in that loop removing or adding some objects to the same object. It is not possible and causes exception.
You can replace that for-loop with for-loop using index variable:
for (int i=0; i<[object count]; i++)
{
//add or remove objects if you want
}