'NSInvalidArgumentException', reason: '*** -getValue: only defined for abstract class. Define -[KotlinInt getValue:]!' - swift

I am using Kotlin multiplatform to build framework for iOS, and everything works well except the strange issue.
The code from Kotlin:
fun example(): Map<Int, Double> {
val result = mutableMapOf<Int, Double>()
result[1] = 9.99
return result
}
Using framework is Swift:
let example = example()
The app will crash and display the trace as following
2019-10-30 15:37:19.096474+0800 Test[73756:3057881] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -getValue: only defined for abstract class. Define -[KotlinInt getValue:]!'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23baa1ee __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50864b20 objc_exception_throw + 48
2 Foundation 0x00007fff2584a6b3 _NSRequestConcreteObject + 0
3 Foundation 0x00007fff256bea7e -[NSNumber copyWithZone:] + 129
4 CoreFoundation 0x00007fff23add550 __NSSingleEntryDictionaryI_new + 128
5 CoreFoundation 0x00007fff23ba56f3 -[NSDictionary initWithDictionary:copyItems:] + 403
6 CoreFoundation 0x00007fff23c07fc7 -[__NSPlaceholderDictionary initWithDictionary:copyItems:] + 135
7 libswiftFoundation.dylib 0x00007fff511ef3a0 $sSD10FoundationE26_forceBridgeFromObjectiveC_6resultySo12NSDictionaryC_SDyxq_GSgztFZ + 192
8 libswiftFoundation.dylib 0x00007fff511e3593 $sSD10FoundationE36_unconditionallyBridgeFromObjectiveCySDyxq_GSo12NSDictionaryCSgFZ + 67
9 Test 0x0000000102f54320 $s4Test11ContentViewV3calSSyF + 1104
10 Test 0x0000000102f53e3b $s4Test11ContentViewV4bodyQrvg + 91
11 Test 0x0000000102f549c1 $s4Test11ContentViewV7SwiftUI0C0AadEP4body4BodyQzvgTW + 17
12 SwiftUI 0x00007fff2bfb1c49 $s7SwiftUI8ViewBody33_9F92ACD17B554E8AB7D29ABB1E796415LLV5applyy0D0QzxF + 585
13 SwiftUI 0x00007fff2bfb2df9 $s7SwiftUI8ViewBody33_9F92ACD17B554E8AB7D29ABB1E796415LLVyxG14AttributeGraph07UntypedM0AafGP7_update_5graph9attributeySv_So10AGGraphRefaSo11AGAttributeatFZTW + 137
14 AttributeGraph 0x00007fff2f8f1849 $sTA + 25
15 AttributeGraph 0x00007fff2f8d9255 _ZN2AG5Graph11UpdateStack6updateEv + 1111
16 AttributeGraph 0x00007fff2f8d9513 _ZN2AG5Graph16update_attributeEjb + 377
17 AttributeGraph 0x00007fff2f8de131 _ZN2AG8Subgraph6updateEj + 929
18 SwiftUI 0x00007fff2c10d100 $s7SwiftUI9ViewGraphC14runTransaction33_D63C4EB7F2B205694B6515509E76E98BLL2inySo10AGGraphRefa_tF + 224
19 SwiftUI 0x00007fff2c10d517 $s7SwiftUI9ViewGraphC13updateOutputs2atyAA4TimeV_tFSb5prefs_Sb9idealSizeAC0F0V7outputstSo10AGGraphRefaXEfU_ + 103
20 SwiftUI 0x00007fff2c10d1d1 $s7SwiftUI9ViewGraphC13updateOutputs2atyAA4TimeV_tF + 145
21 SwiftUI 0x00007fff2c4af579 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_yyXEfU_ + 1001
22 SwiftUI 0x00007fff2c4aef8a $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_ + 634
23 SwiftUI 0x00007fff2c4a4274 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtF + 436
24 SwiftUI 0x00007fff2c65a182 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyF + 226
25 SwiftUI 0x00007fff2c65a1a5 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyFTo + 21
26 UIKitCore 0x00007fff47a52ad5 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
27 QuartzCore 0x00007fff2b06e91d -[CALayer layoutSublayers] + 255
28 QuartzCore 0x00007fff2b073323 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
29 QuartzCore 0x00007fff2b07fa7c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
30 QuartzCore 0x00007fff2afc6e54 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
31 QuartzCore 0x00007fff2affc32f _ZN2CA11Transaction6commitEv + 643
32 UIKitCore 0x00007fff475906cd __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
33 CoreFoundation 0x00007fff23b0d09c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
34 CoreFoundation 0x00007fff23b0c808 __CFRunLoopDoBlocks + 312
35 CoreFoundation 0x00007fff23b07694 __CFRunLoopRun + 1284
36 CoreFoundation 0x00007fff23b06e66 CFRunLoopRunSpecific + 438
37 GraphicsServices 0x00007fff38346bb0 GSEventRunModal + 65
38 UIKitCore 0x00007fff47578dd0 UIApplicationMain + 1621
39 Test 0x0000000102f526fb main + 75
40 libdyld.dylib 0x00007fff516ecd29 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Actually, I want to implement the function to return the Map, but I inspect the type of example() in the Xocde's IDE is [KotlinInt : KotlinDouble]. I don't know how to fix this to use this function in the Xcode normally without the exception.

I thought there is no structure type "Map" in Kotlin corresponding to "Dictionary" in iOS Swift. Try to replace the Map with MutableMap and solve this issue.
fun example(): MutableMap <Int, Double> {
val result = mutableMapOf<Int, Double>()
result[1] = 9.99
return result
}
However, you can also cast the type in Swift for another using. For example,
let example = example() as! [Int64 : Double]

Map exist in kotlin, here an example:
val map = mutableMapOf(1 to 1.2, 2 to 1.2, 3 to 1.5)
println(map)
map[4] = 3.4
println(map)
output:
{1=1.2, 2=1.2, 3=1.5}
{1=1.2, 2=1.2, 3=1.5, 4=3.4}

Related

Calling #selector #objc function through perform crasher

I am calling a function through another view controller with:
perform(#selector(MainScreenViewController().test))
The action is called test and it is located in the MainScreenViewController().
Once it reaches this code the application crashes with the following crash report:
2018-01-20 13:24:46.800692+0100 Business Name[40750:3947268] -[Business_Name.RPLabel test]: unrecognized selector sent to instance 0x7fd444d03e30
2018-01-20 13:24:46.809915+0100 Business Name[40750:3947268] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Business_Name.RPLabel test]: unrecognized selector sent to instance 0x7fd444d03e30'
*** First throw call stack:
(
0 CoreFoundation 0x00000001127621cb __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010de9af41 objc_exception_throw + 48
2 CoreFoundation 0x00000001127e2914 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x000000010f5810bd -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x00000001126e5178 ___forwarding___ + 1432
5 CoreFoundation 0x00000001126e4b58 _CF_forwarding_prep_0 + 120
6 Business Name 0x000000010d54edc2 _T013Business_Name7RPLabelC5setupyyF + 738
7 Business Name 0x000000010d54e705 _T013Business_Name7RPLabelCACSC6CGRectV5frame_tcfc + 325
8 Business Name 0x000000010d54e746 _T013Business_Name7RPLabelCACSC6CGRectV5frame_tcfcTo + 38
9 UIKit 0x000000010f3f3f66 -[UIView init] + 62
10 Business Name 0x000000010d5385a3 _T0So7UILabelCABycfcTO + 19
11 Business Name 0x000000010d53137c _T0So7UILabelCABycfC + 60
12 Business Name 0x000000010d538944 globalinit_33_2857E66F75A5DBE934F5CCD1167A060E_func5 + 20
13 libdispatch.dylib 0x000000011380f43c _dispatch_client_callout + 8
14 libdispatch.dylib 0x00000001138109c7 dispatch_once_f + 297
15 Business Name 0x000000010d538984 _T013Business_Name9mainTitleAA7RPLabelCfau + 36
16 Business Name 0x000000010d5389ae _T013Business_Name10setupTitleyyF + 30
17 Business Name 0x000000010d53fd1f _T013Business_Name24MainScreenViewControllerC13viewDidAppearySbF + 31
18 Business Name 0x000000010d53fe23 _T013Business_Name24MainScreenViewControllerC13viewDidAppearySbFTo + 51
19 UIKit 0x000000010f4fcaaf -[UIViewController _setViewAppearState:isAnimating:] + 699
20 UIKit 0x000000010f55b746 -[UITabBarController viewDidAppear:] + 115
21 UIKit 0x000000010f4fcaaf -[UIViewController _setViewAppearState:isAnimating:] + 699
22 UIKit 0x000000010f4ff959 __64-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]_block_invoke + 42
23 UIKit 0x000000010f4fdc4d -[UIViewController _executeAfterAppearanceBlock] + 86
24 UIKit 0x000000010f364d9d _runAfterCACommitDeferredBlocks + 634
25 UIKit 0x000000010f35330d _cleanUpAfterCAFlushAndRunDeferredBlocks + 280
26 UIKit 0x000000010f374714 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 155
27 CoreFoundation 0x000000011270520c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
28 CoreFoundation 0x00000001126e9a3b __CFRunLoopDoBlocks + 203
29 CoreFoundation 0x00000001126e9214 __CFRunLoopRun + 1300
30 CoreFoundation 0x00000001126e8a89 CFRunLoopRunSpecific + 409
31 GraphicsServices 0x000000011556e9c6 GSEventRunModal + 62
32 UIKit 0x000000010f358d30 UIApplicationMain + 159
33 Business Name 0x000000010d548637 main + 55
34 libdyld.dylib 0x000000011388bd81 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This is the code in test:
#objc func test(){
print("test")
}
MainScreenViewController().perform(#selector(MainScreenViewController().test))

Core Data sync with CouchBase using CBLIncrementalStore crashing

I am using Core Data in my project and now I wanted to add sync features. Rolling my own turned out to be harder than I thought; therefore, I wanted to try ready libraries.
I integrated Couchbase in the project, setup IBM Cloudant for sync gateway and server.
For a very simple project I tested it and everything seems to be working fine. However, when I implement the same solution to the existing project; it crashes sometimes and I don't have the slightest clue how to approach the problem.
p.s. Info if it makes a difference: I had hell of a time with the model update in CBLIncrementStore as the core data kept complaining that it can't modify an immutable model; event though it was not used or attached to persistent store. In the end I had to create a new project, modified the model, and copy the model to my existing project. Then it started working. Even below code, where returning an mutableCopy of the model; didn't work (event though it worked perfectly in an empty project):
EDIT - Normally, no need to return mutableCopy this is something I tried in my particular case. Explained above^^
// MARK: - MODEL
lazy var modelURL: URL = {
let bundle = Bundle.main
if let url = bundle.url(forResource: "couchsync", withExtension: "momd") {
return url
}
DLog("CRITICAL - Managed Object Model file not found")
abort()
}()
lazy var model: NSManagedObjectModel = {
if let mutableModel = NSManagedObjectModel(contentsOf: self.modelURL)?.mutableCopy() as? NSManagedObjectModel {
return mutableModel
}
DLog("CRITICAL - Can't read model")
abort()
}()
The code crashes below in CBLIncrementalStore:
- (NSIncrementalStoreNode*) newValuesForObjectWithID: (NSManagedObjectID*)objectID
withContext: (NSManagedObjectContext*)context
error: (NSError**)outError {
And the debug output is as follows (CDStack.swift is from my project):
[00324]:CDStack.swift :save.......................... :16:15:14 Inserted objects count = 33
2017-04-11 16:15:14.132 MuhApp[23391:1022666] -[__NSCFNumber _fastCStringContents:]: unrecognized selector sent to instance 0xb000000000000001
2017-04-11 16:15:14.142 MuhApp[23391:1022666] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber _fastCStringContents:]: unrecognized selector sent to instance 0xb000000000000001'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c6e3b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010bba0141 objc_exception_throw + 48
2 CoreFoundation 0x000000010c753134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010c66a840 ___forwarding___ + 1024
4 CoreFoundation 0x000000010c66a3b8 _CF_forwarding_prep_0 + 120
5 CoreData 0x000000010c1e9cfd _PFRawFastIndexForKnownKey + 93
6 CoreData 0x000000010c1e9bfe _PFRawIndexForKnownKey + 62
7 CoreData 0x000000010c1ea49c -[NSKnownKeysDictionary1 objectForKey:] + 28
8 MuhApp 0x000000010a184639 __66-[CBLIncrementalStore newValuesForObjectWithID:withContext:error:]_block_invoke_2 + 121
9 CoreData 0x000000010c239b52 developerSubmittedBlockToNSManagedObjectContextPerform + 178
10 CoreData 0x000000010c239a1f -[NSManagedObjectContext performBlockAndWait:] + 239
11 MuhApp 0x000000010a18449e __66-[CBLIncrementalStore newValuesForObjectWithID:withContext:error:]_block_invoke + 670
12 libdispatch.dylib 0x000000011351405c _dispatch_client_callout + 8
13 libdispatch.dylib 0x00000001134f1de6 _dispatch_barrier_sync_f_invoke + 346
14 MuhApp 0x000000010a184033 -[CBLIncrementalStore newValuesForObjectWithID:withContext:error:] + 403
15 CoreData 0x000000010c2ea624 __95-[NSPersistentStoreCoordinator(_NSInternalMethods) newValuesForObjectWithID:withContext:error:]_block_invoke + 100
16 CoreData 0x000000010c2f32f4 gutsOfBlockToNSPersistentStoreCoordinatorPerform + 196
17 libdispatch.dylib 0x000000011351405c _dispatch_client_callout + 8
18 libdispatch.dylib 0x00000001134f1de6 _dispatch_barrier_sync_f_invoke + 346
19 CoreData 0x000000010c2e0785 _perform + 213
20 CoreData 0x000000010c2e0505 -[NSPersistentStoreCoordinator _routeLightweightBlock:toStore:] + 229
21 CoreData 0x000000010c211d01 -[NSPersistentStoreCoordinator(_NSInternalMethods) newValuesForObjectWithID:withContext:error:] + 417
22 CoreData 0x000000010c211218 _PFFaultHandlerLookupRow + 376
23 CoreData 0x000000010c210c9f _PF_FulfillDeferredFault + 239
24 CoreData 0x000000010c2341e2 -[NSManagedObject(_NSInternalMethods) _includeObject:intoPropertyWithKey:andIndex:] + 130
25 CoreData 0x000000010c2339c0 -[NSManagedObject(_NSInternalMethods) _didChangeValue:forRelationship:named:withInverse:] + 576
26 Foundation 0x000000010b6a96dc NSKeyValueNotifyObserver + 351
27 Foundation 0x000000010b6a8f93 NSKeyValueDidChange + 484
28 Foundation 0x000000010b679709 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 111
29 CoreData 0x000000010c21c40d -[NSManagedObject didChangeValueForKey:] + 93
30 CoreData 0x000000010c2a773f -[NSManagedObject(_NSInternalMethods) _updateFromRefreshSnapshot:includingTransients:] + 799
31 CoreData 0x000000010c23fe54 -[NSManagedObjectContext(_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 948
32 CoreData 0x000000010c23f413 -[NSManagedObjectContext(_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 947
33 CoreData 0x000000010c2ba927 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 567
34 CoreData 0x000000010c23a0ea internalBlockToNSManagedObjectContextPerform + 106
35 libdispatch.dylib 0x000000011351405c _dispatch_client_callout + 8
36 libdispatch.dylib 0x00000001134f1de6 _dispatch_barrier_sync_f_invoke + 346
37 CoreData 0x000000010c23a054 _perform + 244
38 CoreData 0x000000010c239e7d -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 301
39 CoreData 0x000000010c221488 -[NSManagedObjectContext save:] + 3368
40 MuhApp 0x000000010a215522 _TFZFC6MuhApp7CDStack4saveFCSo22NSManagedObjectContextT_U_FT_T_ + 610
41 MuhApp 0x000000010a1a0927 _TTRXFo___XFdCb___ + 39
42 CoreData 0x000000010c239b52 developerSubmittedBlockToNSManagedObjectContextPerform + 178
43 CoreData 0x000000010c239a1f -[NSManagedObjectContext performBlockAndWait:] + 239
44 MuhApp 0x000000010a21529b _TZFC6MuhApp7CDStack4savefCSo22NSManagedObjectContextT_ + 187
45 MuhApp 0x000000010a1ded49 _TFC6MuhApp7MUStoreP33_5810EFAD2D482DA23D84CA4C96F2558221createbusinessFoldersfT_GSaCS_9MUAccount_ + 11145
46 MuhApp 0x000000010a1db875 _TFC6MuhApp7MUStoreP33_5810EFAD2D482DA23D84CA4C96F2558228fetchOrCreateBusinessFoldersfT_GSaCS_9MUAccount_ + 133
47 MuhApp 0x000000010a1d4e78 _TFC6MuhApp7MUStoreg15businessFoldersGSaCS_9MUAccount_ + 120
48 MuhApp 0x000000010a236fa0 _TFC6MuhApp23MainTableViewController7preparefT3forCSo17UIStoryboardSegue6senderGSqP___T_ + 1088
49 MuhApp 0x000000010a2380fb _TToFC6MuhApp23MainTableViewController7preparefT3forCSo17UIStoryboardSegue6senderGSqP___T_ + 187
50 UIKit 0x000000010dc158ee -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 353
51 UIKit 0x000000010dc1575c -[UIStoryboardSegueTemplate _perform:] + 82
52 UIKit 0x000000010dc15a1f -[UIStoryboardSegueTemplate perform:] + 157
53 UIKit 0x000000010d5a4d77 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1677
54 UIKit 0x000000010d5a4fe3 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 344
55 UIKit 0x000000010d45a7f3 _runAfterCACommitDeferredBlocks + 318
56 UIKit 0x000000010d4477bc _cleanUpAfterCAFlushAndRunDeferredBlocks + 532
57 UIKit 0x000000010d47928c _afterCACommitHandler + 137
58 CoreFoundation 0x000000010c689717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
59 CoreFoundation 0x000000010c689687 __CFRunLoopDoObservers + 391
60 CoreFoundation 0x000000010c66e720 __CFRunLoopRun + 1200
61 CoreFoundation 0x000000010c66e016 CFRunLoopRunSpecific + 406
62 GraphicsServices 0x0000000110359a24 GSEventRunModal + 62
63 UIKit 0x000000010d44e0d4 UIApplicationMain + 159
64 MuhApp 0x000000010a2a9da7 main + 55
65 libdyld.dylib 0x000000011356065d start + 1
66 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Any ideas how to proceed from here?

-[_SwiftValue unsignedIntegerValue]: unrecognized selector sent to instance 0x608000243d50 (lldb)

I finished migrating my application to swift3 but this section keeps yielding is causing problems.
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationItem.title = artworkTitle
let title = "<center><span style=\"font-size: 17px;font-weight:lighter;font-family:Avenir-Book;\">" + artworkCaption + "</span></center>"
artworkImageView.image = UIImage(named: artworkImagePath)
artworkCaptionView.attributedText = title.html2AttStr
}
Important Console Parts
-[_SwiftValue unsignedIntegerValue]: unrecognized selector sent to instance 0x608000243d50
terminating with uncaught exception of type NSException
(lldb)
extension String
{
var html2AttStr:NSAttributedString
{
let contents: NSMutableAttributedString?
do {
let attrTextStyle = NSMutableParagraphStyle()
attrTextStyle.alignment = NSTextAlignment.center
contents = try NSMutableAttributedString(data: data(using: String.Encoding.utf8)!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8], documentAttributes: nil)
} catch _ {
contents = nil
}
Console
0 CoreFoundation 0x000000010b70934b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ad7521e objc_exception_throw + 48
2 CoreFoundation 0x000000010b778f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010b68ec15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010b68e798 _CF_forwarding_prep_0 + 120
5 UIFoundation 0x0000000114565953 -[NSHTMLReader _loadUsingWebKit] + 1329
6 UIFoundation 0x0000000114566f15 -[NSHTMLReader attributedString] + 22
7 UIFoundation 0x00000001144fd45c _NSReadAttributedStringFromURLOrData + 5779
8 UIFoundation 0x00000001144fbd35 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 115
9 pg 0x000000010a39fe1d _TTOFCSo25NSMutableAttributedStringcfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S_ + 173
10 pg 0x000000010a39fba4 _TFCSo25NSMutableAttributedStringCfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S_ + 100
11 pg 0x000000010a39f96a _TFE2pgSSg11html2AttStrCSo18NSAttributedString + 458
12 pg 0x000000010a3a901d _TFC2pg21ViewControllerArtwork14viewWillAppearfSbT_ + 1197
13 pg 0x000000010a3a90b1 _TToFC2pg21ViewControllerArtwork14viewWillAppearfSbT_ + 49
14 UIKit 0x000000010c642de3 -[UIViewController _setViewAppearState:isAnimating:] + 692
15 UIKit 0x000000010c6434f3 -[UIViewController __viewWillAppear:] + 147
16 UIKit 0x000000010c67e1a3 -[UINavigationController _startTransition:fromViewController:toViewController:] + 890
17 UIKit 0x000000010c67f0b9 -[UINavigationController _startDeferredTransitionIfNeeded:] + 874
18 UIKit 0x000000010c68019b -[UINavigationController __viewWillLayoutSubviews] + 58
19 UIKit 0x000000010c8771b7 -[UILayoutContainerView layoutSubviews] + 223
20 UIKit 0x000000010c560344 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
21 QuartzCore 0x000000010c312cdc -[CALayer layoutSublayers] + 146
22 QuartzCore 0x000000010c3067a0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
23 QuartzCore 0x000000010c30661e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
24 QuartzCore 0x000000010c29462c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
25 QuartzCore 0x000000010c2c1713 _ZN2CA11Transaction6commitEv + 475
26 UIKit 0x000000010c495067 _UIApplicationFlushRunLoopCATransactionIfTooLate + 206
27 UIKit 0x000000010cca4b30 __handleEventQueue + 5672
28 CoreFoundation 0x000000010b6ae311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
29 CoreFoundation 0x000000010b69359c __CFRunLoopDoSources0 + 556
30 CoreFoundation 0x000000010b692a86 __CFRunLoopRun + 918
31 CoreFoundation 0x000000010b692494 CFRunLoopRunSpecific + 420
32 GraphicsServices 0x0000000111084a6f GSEventRunModal + 161
33 UIKit 0x000000010c49bf34 UIApplicationMain + 159
34 pg 0x000000010a3acaaf main + 111
35 libdyld.dylib 0x000000011233668d start + 1
36 ??? 0x0000000000000001 0x0 + 1
libc++abi.dylib: terminating with uncaught exception of type NSException
I remember reading on Apple's Swift blog that if you get unrecognized selector errors, it means that the auto-wrapping of Swift structs are causing issues. Most likely it is wrapping String.Encoding instead of converting it to an NSNumber (what the Objective-C code behind NSMutableAttributedString is expecting).
Try replacing NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 with NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue

Swift : Terminating app with uncaught exception of NSExeption?

Before you say "this is a repeat of a question", no. I have checked the question before and all it tells me is to check my outlets. All my outlets are correct and I'm not sure why I'm getting this error. Here's the error in detail :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString objectForKeyedSubscript:]: unrecognized selector sent to instance 0xa00000000006e652'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ddf5d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010d85e21e objc_exception_throw + 48
2 CoreFoundation 0x000000010de65f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010dd7b005 ___forwarding___ + 1013
4 CoreFoundation 0x000000010dd7ab88 _CF_forwarding_prep_0 + 120
5 Calc 0x0000000108d00b37 -[MPCoreInstanceProvider appTransportSecuritySettings] + 284
6 Calc 0x0000000108cc4147 +[MPAdServerURLBuilder queryParameterForAppTransportSecurity] + 76
7 Calc 0x0000000108cc30d4 +[MPAdServerURLBuilder URLWithAdUnitID:keywords:location:versionParameterName:version:testing:desiredAssets:adSequence:] + 1674
8 Calc 0x0000000108cc2a01 +[MPAdServerURLBuilder URLWithAdUnitID:keywords:location:versionParameterName:version:testing:desiredAssets:] + 173
9 Calc 0x0000000108cc2920 +[MPAdServerURLBuilder URLWithAdUnitID:keywords:location:testing:] + 116
10 Calc 0x0000000108cd3cde -[MPBannerAdManager loadAdWithURL:] + 470
11 Calc 0x0000000108cc03a2 -[MPAdView loadAd] + 48
12 Calc 0x000000010895aa1f _TFFC4Calc18MenuViewController11viewDidLoadFT_T_L_7loadAdsfT_T_ + 175
13 Calc 0x0000000108957d18 _TFC4Calc18MenuViewController11viewDidLoadfT_T_ + 8104
14 Calc 0x000000010895b632 _TToFC4Calc18MenuViewController11viewDidLoadfT_T_ + 34
15 UIKit 0x00000001099cb8b1 -[UIViewController loadViewIfRequired] + 1258
16 UIKit 0x00000001099cbce4 -[UIViewController view] + 27
17 UIKit 0x0000000109895405 -[UIWindow addRootViewControllerViewIfPossible] + 71
18 UIKit 0x0000000109895b56 -[UIWindow _setHidden:forced:] + 293
19 UIKit 0x00000001098a9469 -[UIWindow makeKeyAndVisible] + 42
20 Calc 0x0000000108c32264 _TFC4Calc11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryVSC29UIApplicationLaunchOptionsKeyP____Sb + 5716
21 Calc 0x0000000108c34674 _TToFC4Calc11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryVSC29UIApplicationLaunchOptionsKeyP____Sb + 180
22 UIKit 0x0000000109820312 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 290
23 UIKit 0x0000000109821c97 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4236
24 UIKit 0x000000010982803d -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
25 UIKit 0x00000001098251bd -[UIApplication workspaceDidEndTransaction:] + 188
26 FrontBoardServices 0x00000001160176cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
27 FrontBoardServices 0x0000000116017544 -[FBSSerialQueue _performNext] + 189
28 FrontBoardServices 0x00000001160178cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
29 CoreFoundation 0x000000010dd9a761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30 CoreFoundation 0x000000010dd7f98c __CFRunLoopDoSources0 + 556
31 CoreFoundation 0x000000010dd7ee76 __CFRunLoopRun + 918
32 CoreFoundation 0x000000010dd7e884 CFRunLoopRunSpecific + 420
33 UIKit 0x0000000109823a3a -[UIApplication _run] + 434
34 UIKit 0x0000000109829bb8 UIApplicationMain + 159
35 Calc 0x0000000108c4617f main + 111
36 libdyld.dylib 0x0000000110df668d start + 1
37 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Looks like the Info.plist of your app may not have a proper values for NSAppTransportSecurity or one of its children.
Check out: MPCoreInstanceProvider.m.
"this is a repeat of a question" - next time look at your stack trace, it contains all the hints required:
Close to the top you have the -[NSObject(NSObject) doesNotRecognizeSelector:] which is throwing the exception (objc_exception_throw ...)
doesNotRecognizeSelector means that some code tried to invoke a method which is not available
which one? Look further above: -[NSTaggedPointerString objectForKeyedSubscript:]
so the method missing is objectForKeyedSubscript: which is what the Objective-C compiler generates for an expression like: myObject[#"title"]
it also tells you the class of the object the method is invoked on: NSTaggedPointerString, so some code tried to use [] on a plain string, which doesn't make much sense
Next thing to check is who invoked that code: -[MPCoreInstanceProvider appTransportSecuritySettings] is the last regular code in the stack
so you DuckDuckGo MPCoreInstanceProvider and find MPCoreInstanceProvider.m
which happens to have a appTransportSecuritySettings method
looking into the code it grabs a dictionary NSDictionary *atsSettingsDictionary = [NSBundle mainBundle].infoDictionary[kMoPubAppTransportSecurityDictionaryKey];
and then does a lot of [] operations on that dictionary and values of it
Conclusion: One of the [] is hitting a string when it was expecting a dictionary.

Xcode - Storyboard compilation failed

On Running the application on iPhone, Build got failed with the following error on compiling Root.Storyboard. But this failure not happening overtime. This happens randomly.
14:59:57 2016-08-02 14:59:45.730 Interface Builder Cocoa Touch Tool[3825:17239088] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '{objective 0x7fa3cd88fe70: <1:5.34034> + <1:0.0320392>*0x7fa3cbef2f20:UISV-fill-proportionally.negError{id: 6394} + <1:-0.0320392>*0x7fa3cbef2f20:UISV-fill-proportionally.posErrorMarker{id: 6393} + <1:-0.0166546>*0x7fa3cd865df0:UISV-spacing.marker{id: 5980} + <1:-0.0166546>*0x7fa3cd86a290:UISV-canvas-connection.marker{id: 5978} + <1:1>*0x7fa3cd86f760:UISV-fill-proportionally.negError{id: 5717} + <1:-0.0166546>*0x7fa3cd899a00:UISV-spacing.marker{id: 5981} + <1:-1.94859>*0x7fa3cd89bc40:UISV-fill-proportionally.negError{id: 5936} + <1:1.94859>*0x7fa3cd89bc40:UISV-fill-proportionally.posErrorMarker{id: 5935} + <1:0.0333092>*0x7fa3cd8a63e0:UISV-fill-equally.marker{id: 5985} + <1:0.0166546>*0x7fa3cd8a7d30:UISV-canvas-connection.marker{id: 6008} + <1:-0.0166546>*0x7fa3cd8ab0e0:UISV-canvas-connection.marker{id: 6009} + <1:1.94859>*0x7fa3cd8abc30.negError{id: 5906} + <1:0.0166546>*0x7fa3cd8c6a10:UISV-canvas-connection.marker{id: 5976} + <1:-0.0166546>*0x7fa3cd8de630:UISV-fill-equally.marker{id: 5984} + <1:-0.0166546>*0x7fa3cd8eb6f0:UISV-spacing.marker{id: 6040} + <1:1>*0x7fa3cdd1b550.marker{id: 6266}}: internal error. Setting empty vector for variable 0x7fa3cd8701b0.negError{id: 5693}.'
14:59:57 *** First throw call stack:
14:59:57 (
14:59:57 0 CoreFoundation 0x0000000112bc7d85 __exceptionPreprocess + 165
14:59:57 1 libobjc.A.dylib 0x0000000112639deb objc_exception_throw + 48
14:59:57 2 CoreFoundation 0x0000000112bc7cbd +[NSException raise:format:] + 205
14:59:57 3 Foundation 0x000000011220dacc -[NSISObjectiveLinearExpression setPriorityVector:forKnownAbsentVariable:] + 76
14:59:57 4 Foundation 0x00000001123b0c44 __128-[NSISObjectiveLinearExpression replaceVariable:withExpression:processVariableNewToReceiver:processVariableDroppedFromReceiver:]_block_invoke + 297
14:59:57 5 Foundation 0x000000011220a6bf -[NSISLinearExpression enumerateVariablesAndCoefficients:] + 350
14:59:57 6 Foundation 0x00000001123b0b04 -[NSISObjectiveLinearExpression replaceVariable:withExpression:processVariableNewToReceiver:processVariableDroppedFromReceiver:] + 369
14:59:57 7 Foundation 0x000000011220b7ee -[NSISEngine substituteOutAllOccurencesOfBodyVar:withExpression:] + 633
14:59:57 8 Foundation 0x000000011220e789 -[NSISEngine pivotToMakeBodyVar:newHeadOfRowWithHead:andDropRow:] + 330
14:59:57 9 Foundation 0x000000011220c082 -[NSISEngine minimizeConstantInObjectiveRowWithHead:] + 146
14:59:57 10 Foundation 0x00000001123acacf -[NSISEngine _optimizeWithoutRebuilding] + 158
14:59:57 11 Foundation 0x000000011220bc0f -[NSISEngine optimize] + 46
14:59:57 12 Foundation 0x000000011220c42d -[NSISEngine withBehaviors:performModifications:] + 245
14:59:57 13 UIKit 0x00000001103b9adb -[UIView(AdditionalLayoutSupport) _withAutomaticEngineOptimizationDisabledIfEngineExists:] + 58
14:59:57 14 UIKit 0x00000001103ba61e -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 254
14:59:57 15 UIKit 0x00000001103aac47 -[UIWindow(UIConstraintBasedLayout) updateConstraintsIfNeeded] + 108
14:59:57 16 UIKit 0x00000001103bb333 -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 272
14:59:57 17 UIKit 0x000000010fb6fa96 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 159
14:59:57 18 UIKit 0x000000010fb4c6f6 -[UIWindow layoutSubviews] + 43
14:59:57 19 UIKit 0x000000010fb7f980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
14:59:57 20 QuartzCore 0x000000011209dc00 -[CALayer layoutSublayers] + 146
14:59:57 21 QuartzCore 0x000000011209208e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
14:59:57 22 QuartzCore 0x0000000112091f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14:59:57 23 QuartzCore 0x00000001120863c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
14:59:57 24 QuartzCore 0x00000001120b4086 _ZN2CA11Transaction6commitEv + 486
14:59:57 25 QuartzCore 0x00000001120b47f8 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
14:59:57 26 CoreFoundation 0x0000000112aecc37 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
14:59:57 27 CoreFoundation 0x0000000112aecba7 __CFRunLoopDoObservers + 391
14:59:57 28 CoreFoundation 0x0000000112ae211c CFRunLoopRunSpecific + 524
14:59:57 29 Foundation 0x0000000112222a31 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 267
14:59:57 30 IBFoundation 0x0000000111e8330f -[IBAbstractPlatformTool startServingReceiveChannel:] + 429
14:59:57 31 IBFoundation 0x0000000111e834ee -[IBAbstractPlatformTool startServingWriteDescriptor:readDescriptor:] + 117
14:59:57 32 IBFoundation 0x0000000111e83fea +[IBAbstractPlatformTool main] + 1177
14:59:57 33 Interface Builder Cocoa Touch Tool 0x000000010f96abe7 Interface Builder Cocoa Touch Tool + 3047
14:59:57 34 libdyld.dylib 0x00000001169ab92d start + 1
14:59:57 )
14:59:57 libc++abi.dylib: terminating with uncaught exception of type NSException
14:59:58 Command /Applications/Xcode.app/Contents/Developer/usr/bin/ibtool failed with exit code 255
Thanks in advance.