I have a dictionary:
var swiftBlogs:[Message] = [Message]()
My message class:
class Message: Object {
#objc dynamic var incoming=false
#objc dynamic var text = ""
#objc dynamic var from = ""
#objc dynamic var fromMe = 0
#objc dynamic var roomName = ""
#objc dynamic var time=0
#objc dynamic var isInfo=false
#objc dynamic var me=""
#objc dynamic var messageId=0
#objc dynamic var localId=0
#objc dynamic var isSent=1
#objc dynamic var isRibbon=0
#objc dynamic var ribbonJson = ""
#objc dynamic var isImage=0
#objc dynamic var isVoice=0
#objc dynamic var serverTime=0
}
I am updating the sent status for some messages like this:
let messageInfo:Dictionary<String,Message?> = notification.userInfo as! Dictionary<String,Message?>
let m1 = messageInfo["m"]
if let i = swiftBlogs.index(where: {$0.localId == m1!?.localId}) {
swiftBlogs[i].isSent=1
}
Actually it is working well but i see too many crash reports from my users for this line:
if let i = swiftBlogs.index(where: {$0.localId == m1!?.localId}) {
Exception:
2 Realm 0x10498ec08 long long (anonymous namespace)::get<long long>(RLMObjectBase*, unsigned long) + 164 (RLMObject_Private.hpp:45)
Full crash log:
Last Exception Backtrace:
0 CoreFoundation 0x18d080518 __exceptionPreprocess + 228
1 libobjc.A.dylib 0x18c25b9f8 objc_exception_throw + 55
2 Realm 0x10498ec08 long long (anonymous namespace)::get<long long>(RLMObjectBase*, unsigned long) + 164 (RLMObject_Private.hpp:45)
3 Ribony 0x1041a4f34 ChatViewController.processIsSent(_:) + 772 (ChatViewController.swift:396)
4 Ribony 0x1041a9e8c #objc ChatViewController.processMessage(_:) + 108
5 CoreFoundation 0x18cff15bc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 19
6 CoreFoundation 0x18cff1588 ___CFXRegistrationPost_block_invoke + 63
7 CoreFoundation 0x18cff0a7c _CFXRegistrationPost + 391
8 CoreFoundation 0x18cff0728 ___CFXNotificationPost_block_invoke + 95
9 CoreFoundation 0x18cf6a524 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1495
10 CoreFoundation 0x18cff01d8 _CFXNotificationPost + 695
11 Foundation 0x18d9d8814 -[NSNotificationCenter postNotificationName:object:userInfo:] + 67
12 Ribony 0x1041249cc closure #1 in closure #1 in ChatManager.sendMessage(_:to:anonClosed:toWeb:localId:isFirstReply:is... + 536 (ChatManager.swift:499)
13 RealmSwift 0x104de45fc Realm.write(_:) + 60 (Realm.swift:155)
14 Ribony 0x104124734 closure #1 in ChatManager.sendMessage(_:to:anonClosed:toWeb:localId:isFirstReply:isRibbon:isImage... + 512 (ChatManager.swift:495)
15 SocketIO 0x104e8dfd8 SocketIOClient.handleAck(_:data:) + 352 (SocketAckManager.swift:70)
16 SocketIO 0x104e8e7c8 SocketIOClient.handlePacket(_:) + 596 (SocketIOClient.swift:362)
17 SocketIO 0x104ea01c0 specialized SocketManager._parseEngineMessage(_:) + 704 (SocketManager.swift:401)
18 SocketIO 0x104e9f50c partial apply for closure #1 in SocketManager.engineDidClose(reason:) + 32
19 SocketIO 0x104e7339c thunk for #escaping #callee_guaranteed () -> () + 28 (<compiler-generated>:0)
20 libdispatch.dylib 0x18cac0a38 _dispatch_call_block_and_release + 23
21 libdispatch.dylib 0x18cac17d4 _dispatch_client_callout + 15
22 libdispatch.dylib 0x18ca6f004 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1067
23 CoreFoundation 0x18d011ec0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 11
24 CoreFoundation 0x18d00cdf8 __CFRunLoopRun + 1923
25 CoreFoundation 0x18d00c354 CFRunLoopRunSpecific + 435
26 GraphicsServices 0x18f20c79c GSEventRunModal + 103
27 UIKitCore 0x1b95f7b68 UIApplicationMain + 211
28 Ribony 0x1040fa3a4 main + 68 (ConversationModel.swift:16)
29 libdyld.dylib 0x18cad28e0 start + 3
Where is the problem?
Related
I need to write some quick test for a Swift-PFObject (using Subclassing), my class:
class Category: PFObject, PFSubclassing {
#NSManaged var name : String!
#NSManaged var detail : String!
#NSManaged var iconUrl : String!
#NSManaged var imageUrl: String!
#NSManaged var people : PFRelation!
override class func initialize() {
var onceToken : dispatch_once_t = 0;
dispatch_once(&onceToken) {
self.registerSubclass()
}
}
class func parseClassName() -> String {
return "Category"
}
}
My Test implementation (not completed yet) :
class CategorySpec: QuickSpec {
override func spec() {
var category = Category()
.
.
.
}
}
I've checked the 'Target Membership' for Tests in Category class: (not using public keyword in my class and methods).
This is the stack trace when run the test:
2015-08-04 23:52:07.314 SnipMe[14216:127914] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to register both SnipMe.Category and SnipMeTests.Category as the native PFObject subclass of Category. Cannot determine the right class to use because neither inherits from the other.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010fa64c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010feffbb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010fa64b9d +[NSException raise:format:] + 205
3 Parse 0x000000010e0d9a67 +[PFObject registerSubclass] + 536
4 SnipMeTests 0x000000011c6b77ef _TFZFC11SnipMeTests8Category10initializeFMS0_FT_T_U_FT_T_ + 63
5 SnipMeTests 0x000000011c6b7187 _TTRXFo__dT__XFdCb__dT__ + 39
6 libdispatch.dylib 0x0000000111360964 _dispatch_client_callout + 8
7 libdispatch.dylib 0x000000011134e902 dispatch_once_f + 129
8 SnipMeTests 0x000000011c6b727a _TZFC11SnipMeTests8Category10initializefMS0_FT_T_ + 234
9 SnipMeTests 0x000000011c6b7359 _TToZFC11SnipMeTests8Category10initializefMS0_FT_T_ + 25
10 libobjc.A.dylib 0x000000010ff004d6 _class_initialize + 648
11 libobjc.A.dylib 0x000000010ff096e1 lookUpImpOrForward + 351
12 libobjc.A.dylib 0x000000010ff160d3 objc_msgSend + 211
13 SnipMeTests 0x000000011c6b7437 _TMaC11SnipMeTests8Category + 39
14 SnipMeTests 0x000000011c6b4d88 _TFC11SnipMeTests12CategorySpec4specfS0_FT_T_ + 24
15 SnipMeTests 0x000000011c6b4eb2 _TToFC11SnipMeTests12CategorySpec4specfS0_FT_T_ + 34
16 Quick 0x000000011c7e673a +[QuickSpec initialize] + 202
17 libobjc.A.dylib 0x000000010ff004d6 _class_initialize + 648
18 libobjc.A.dylib 0x000000010ff096e1 lookUpImpOrForward + 351
19 libobjc.A.dylib 0x000000010ff160d3 objc_msgSend + 211
20 CoreFoundation 0x000000010f9999ad -[__NSSetM member:] + 77
21 CoreFoundation 0x000000010f987da6 -[NSSet containsObject:] + 22
22 XCTest 0x000000011c6d975a +[XCTestCase(RuntimeUtilities) allSubclasses] + 159
23 XCTest 0x000000011c6cc59c +[XCTestSuite _suiteForBundleCache] + 183
24 XCTest 0x000000011c6cc777 +[XCTestSuite suiteForBundleCache] + 34
25 XCTest 0x000000011c6ccb0a +[XCTestSuite allTests] + 56
26 XCTest 0x000000011c6da83a __33+[XCTestProbe specifiedTestSuite]_block_invoke + 87
27 libdispatch.dylib 0x0000000111360964 _dispatch_client_callout + 8
28 libdispatch.dylib 0x000000011134e902 dispatch_once_f + 129
29 XCTest 0x000000011c6da7e1 +[XCTestProbe specifiedTestSuite] + 98
30 XCTest 0x000000011c6daada +[XCTestProbe runTests:] + 112
31 Foundation 0x000000010d9d61e5 __NSFireDelayedPerform + 387
32 CoreFoundation 0x000000010f9cc174 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
33 CoreFoundation 0x000000010f9cbd35 __CFRunLoopDoTimer + 1045
34 CoreFoundation 0x000000010f98dd3d __CFRunLoopRun + 1901
35 CoreFoundation 0x000000010f98d366 CFRunLoopRunSpecific + 470
36 GraphicsServices 0x0000000113027a3e GSEventRunModal + 161
37 UIKit 0x000000010e4b98c0 UIApplicationMain + 1282
38 SnipMe 0x000000010d4e7f67 main + 135
39 libdyld.dylib 0x0000000111391145 start + 1
40 ??? 0x000000000000000a 0x0 + 10
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Any ideas please? thanks in advance.
My application crash when i use below code.
var char : Character = "1"
var char2 : Character = "1"
func changeChar( char1: inout Character,char2: inout Character) {
char = "b"
char2 = "b"
}
override func viewDidAppear(_ animated: Bool) {
print(char,char2)
changeChar(char1: &char, char2: &char2)
print(char,char2)
}
Error:
Simultaneous accesses to 0x100e0ec50, but modification requires exclusive access.
Previous access (a modification) started at PPlayerNew`ViewController.viewDidAppear(_:) + 340 (0x1000eeda8).
Current access (a modification) started at:
0 libswiftCore.dylib 0x00000001004b9a38 swift_beginAccess + 468
1 PPlayerNew 0x00000001000ee960 ViewController.char.setter + 92
2 PPlayerNew 0x00000001000eebbc ViewController.changeChar(char1:char2:) + 96
3 PPlayerNew 0x00000001000eec54 ViewController.viewDidAppear(_:) + 436
4 PPlayerNew 0x00000001000eef98 #objc ViewController.viewDidAppear(_:) + 64
5 UIKit 0x000000018b3cc5c0 <redacted> + 856
6 UIKit 0x000000018b439630 <redacted> + 44
7 UIKit 0x000000018b43959c <redacted> + 92
8 UIKit 0x000000018b641470 <redacted> + 556
9 UIKit 0x000000018b633420 <redacted> + 528
10 UIKit 0x000000018b64c7b4 <redacted> + 152
11 CoreFoundation 0x00000001852312f8 <redacted> + 20
12 CoreFoundation 0x0000000185230a08 <redacted> + 288
13 CoreFoundation 0x000000018522e6c0 <redacted> + 728
14 CoreFoundation 0x000000018515ebfc CFRunLoopRunSpecific + 424
15 GraphicsServices 0x0000000186bc9010 GSEventRunModal + 100
16 UIKit 0x000000018b419bcc UIApplicationMain + 208
17 PPlayerNew 0x00000001000f0570 main + 76
18 libdyld.dylib 0x000000018416d598 <redacted> + 4
But when i use single param function, like below. code is working
func changeChar( char1: inout Character) {
char = "b"
}
So my main goal is to use inout function with multiple parameters.How can i do this or what's wrong with my code?
Thank You.
You’re changing the property char in your func instead of the parameter char1.
While testing on device (Apple Watch) attempting to save an HKWorkout into HealthKit I am adding samples of distance samples, calories, heart rates and vo2Max to the workout. Unfortunately unlike this question I am not getting as detailed as a trace back...as far as I can tell it's crashing on adding a sample but I can't tell which sample it is or why?
Code:
private func addSamples(toWorkout workout: HKWorkout, from startDate: Date, to endDate: Date, handler: #escaping (Bool, Error?) -> Void) {
let vo2MaxSample = HKQuantitySample(type: HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.vo2Max)!, quantity: vo2MaxQuantity(), start: startDate, end: endDate)
var samples = [HKQuantitySample]()
for distanceWalkingRunningSample in distanceWalkingRunningSamples {
samples.append(distanceWalkingRunningSample)
}
for energySample in energySamples {
samples.append(energySample)
}
samples.append(vo2MaxSample)
samples.append(contentsOf: heartRateValues)
// Add samples to workout
healthStore.add(samples, to: workout) { (success: Bool, error: Error?) in
if error != nil {
print("Adding workout subsamples failed with error: \(String(describing: error))")
handler(false, error)
}
if success {
print("Success, samples have been added, workout Saved.") //WorkoutStartDate = \(workout.startDate) WorkoutEndDate = \(workout.endDate)
handler(true, nil)
} else {
print("Adding workout subsamples failed no error reported")
handler(false, nil)
}
}
}
Trace:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Application Specific Information:
abort() called
Filtered syslog:
None found
Last Exception Backtrace:
0 CoreFoundation 0x1bdf75e8 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x1b15717c objc_exception_throw + 33
2 CoreFoundation 0x1bdf752c +[NSException raise:format:] + 103
3 HealthKit 0x273dbdde -[HKObject _validateForCreation] + 111
4 HealthKit 0x273dbc48 +[HKObject _newDataObjectWithMetadata:device:config:] + 219
5 HealthKit 0x273dbb30 +[HKSample _newSampleWithType:startDate:endDate:device:metadata:config:] + 159
6 HealthKit 0x273e9ba8 +[HKWorkout _workoutWithActivityType:startDate:endDate:workoutEvents:duration:totalActiveEnergyBurned:totalBasalEnergyBurned:totalDistance:totalSwimmingStrokeCount:totalFlightsClimbed:goalType:goal:device:metadata:config:] + 431
7 HealthKit 0x274a9342 +[HKWorkout workoutWithActivityType:startDate:endDate:workoutEvents:totalEnergyBurned:totalDistance:device:metadata:] + 109
8 HealthKit 0x274a9160 +[HKWorkout workoutWithActivityType:startDate:endDate:workoutEvents:totalEnergyBurned:totalDistance:metadata:] + 87
9 Watch Extension 0x002b7ecc 0x290000 + 163532
10 Watch Extension 0x002b79fc 0x290000 + 162300
11 Watch Extension 0x002bb7ac 0x290000 + 178092
12 Watch Extension 0x002ab9e8 0x290000 + 113128
13 Watch Extension 0x002a9660 0x290000 + 104032
14 Watch Extension 0x002a8f68 0x290000 + 102248
15 Watch Extension 0x002a7748 0x290000 + 96072
16 libdispatch.dylib 0x1b8875ec _dispatch_call_block_and_release + 5
17 libdispatch.dylib 0x1b8875c8 _dispatch_client_callout + 1
18 libdispatch.dylib 0x1b897822 _dispatch_main_queue_callback_4CF$VARIANT$mp + 853
19 CoreFoundation 0x1bdb31ac __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 5
20 CoreFoundation 0x1bdb0f42 __CFRunLoopRun + 929
21 CoreFoundation 0x1bcfe96a CFRunLoopRunSpecific + 349
22 GraphicsServices 0x1d8beb92 GSEventRunModal + 89
23 UIKit 0x21f556da UIApplicationMain + 151
24 libxpc.dylib 0x1bb2fd78 _xpc_objc_main + 581
25 libxpc.dylib 0x1bb31720 xpc_main + 149
26 Foundation 0x1c7bbf24 -[NSXPCListener resume] + 175
27 PlugInKit 0x22ccbf40 -[PKService run] + 709
28 WatchKit 0x2b5777b8 main + 157
29 libdyld.dylib 0x1b8e2b8e 0x1b8df000 + 15246
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x1b9e443c __pthread_kill + 8
1 libsystem_pthread.dylib 0x1baec270 pthread_kill$VARIANT$mp + 334
2 libsystem_c.dylib 0x1b96d28e abort + 106
3 libc++abi.dylib 0x1b136cfe __cxa_bad_cast + 0
4 libc++abi.dylib 0x1b136e8a default_unexpected_handler+ 16010 () + 0
5 libobjc.A.dylib 0x1b1573e0 _objc_terminate+ 29664 () + 102
6 libc++abi.dylib 0x1b1493fc std::__terminate(void (*)+ 91132 ()) + 6
7 libc++abi.dylib 0x1b148ed6 __cxxabiv1::exception_cleanup_func+ 89814 (_Unwind_Reason_Code, _Unwind_Exception*) + 0
8 libobjc.A.dylib 0x1b157274 _objc_exception_destructor+ 29300 (void*) + 0
9 CoreFoundation 0x1bdf7530 -[NSException initWithCoder:] + 0
10 HealthKit 0x273dbde2 -[HKObject _validateForCreation] + 116
11 HealthKit 0x273dbc4c +[HKObject _newDataObjectWithMetadata:device:config:] + 224
12 HealthKit 0x273dbb34 +[HKSample _newSampleWithType:startDate:endDate:device:metadata:config:] + 164
13 HealthKit 0x273e9bac +[HKWorkout _workoutWithActivityType:startDate:endDate:workoutEvents:duration:totalActiveEnergyBurned:totalBasalEnergyBurned:totalDistance:totalSwimmingStrokeCount:totalFlightsClimbed:goalType:goal:device:metadata:config:] + 436
14 HealthKit 0x274a9346 +[HKWorkout workoutWithActivityType:startDate:endDate:workoutEvents:totalEnergyBurned:totalDistance:device:metadata:] + 114
15 HealthKit 0x274a9164 +[HKWorkout workoutWithActivityType:startDate:endDate:workoutEvents:totalEnergyBurned:totalDistance:metadata:] + 92
16 Watch Extension 0x002b7ed0 0x290000 + 163536
17 Watch Extension 0x002b7a00 0x290000 + 162304
18 Watch Extension 0x002bb7b0 0x290000 + 178096
19 Watch Extension 0x002ab9ec 0x290000 + 113132
20 Watch Extension 0x002a9664 0x290000 + 104036
21 Watch Extension 0x002a8f6c 0x290000 + 102252
22 Watch Extension 0x002a774c 0x290000 + 96076
23 libdispatch.dylib 0x1b8875f0 _dispatch_call_block_and_release + 10
24 libdispatch.dylib 0x1b8875cc _dispatch_client_callout + 6
25 libdispatch.dylib 0x1b897826 _dispatch_main_queue_callback_4CF$VARIANT$mp + 858
26 CoreFoundation 0x1bdb31b0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 10
27 CoreFoundation 0x1bdb0f46 __CFRunLoopRun + 934
28 CoreFoundation 0x1bcfe96e CFRunLoopRunSpecific + 354
29 GraphicsServices 0x1d8beb96 GSEventRunModal + 94
30 UIKit 0x21f556de UIApplicationMain + 156
31 libxpc.dylib 0x1bb2fd7c _xpc_objc_main + 586
32 libxpc.dylib 0x1bb31724 xpc_main + 154
33 Foundation 0x1c7bbf28 service_connection_handler + 0
34 PlugInKit 0x22ccbf44 -[PKService run] + 714
35 WatchKit 0x2b5777bc main + 162
36 libdyld.dylib 0x1b8e2b92 start + 2
I have my Cordova app on iOS starting up from a significant location change, and sometimes when it starts this way, it crashes while opening its database. I'm not sure what conditions cause this - I haven't been able to reproduce it myself, I've just had reports on Crashlytics; it looks like it affects only some devices.
Here's my code:
class Database {
static let DB_DIR:URL = {
// Library/LocalDatabase doesn't get backed up to iTunes/iCloud, and it matches our sqlite plugin's default (for Javascript access)
let fileMgr = FileManager.default
let libUrl:URL = try! fileMgr.url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
return libUrl.appendingPathComponent("LocalDatabase")
}()
static func getPath(_ dbName:String!) -> String {
return DB_DIR.appendingPathComponent(dbName).path
}
static func createDb(_ dbName:String!) -> FMDatabase {
return FMDatabase(path: getPath(dbName))
}
// only for front- and back-end dbs (TODO - close these when app exits, or open/close for each transaction?)
static func getOpenedDb(_ dbName:String) -> FMDatabase {
let db:FMDatabase = createDb(dbName)
if !db.open() {
fatalError("Unable to open \(dbName)")
}
return db
}
static let BACKEND_DB:FMDatabase = Database.getOpenedDb("mainIosDb")
static let FRONTEND_DB:FMDatabase = Database.getOpenedDb("JsDb")
}
... and here's a crash log:
Crashed: com.rsginc.rmove.TripStorage.singleton
0 libswiftCore.dylib 0x1008c8a18 _TFs16_assertionFailedFTVs12StaticStringSSS_Su5flagsVs6UInt32_Os5Never + 164
1 rMove 0x10022dc88 type metadata accessor for Database (Utilities.swift)
2 rMove 0x10022d320 globalinit_33_2CFFAAA7EF6073F07DB88164E80B793B_func11 (Utilities.swift:177)
3 libdispatch.dylib 0x188c6e1bc _dispatch_client_callout + 16
4 libdispatch.dylib 0x188c6efb0 dispatch_once_f + 56
5 rMove 0x10022d35c Database.BACKEND_DB.unsafeMutableAddressor (Utilities.swift)
6 rMove 0x100213864 TripStorage.init() -> TripStorage (TripStorage.swift:13)
7 rMove 0x100213508 static TripStorage.(getInstance() -> TripStorage).(closure #1) (TripStorage.swift:87)
8 libdispatch.dylib 0x188c6e1bc _dispatch_client_callout + 16
9 libdispatch.dylib 0x188c7b7f0 _dispatch_barrier_sync_f_invoke + 84
10 rMove 0x100213418 static TripStorage.getInstance() -> TripStorage (TripStorage.swift)
11 rMove 0x10020384c specialized CordovaInterface.start(Double, Double, Int, Double, Double, String, Bool, Int, Int, Double, Int, Int, Int, Int) -> () (CordovaInterface.swift)
12 rMove 0x1001fea74 CordovaInterface.configureFromDefaults() -> () (CordovaInterface.swift)
13 rMove 0x1002014fc partial apply (CordovaInterface.swift)
14 rMove 0x10020b1e0 specialized TerminationRecovery.applicationLaunched(notification : NSNotification) -> () (TerminationRecovery.swift)
15 rMove 0x10020a020 #objc TerminationRecovery.applicationLaunched(notification : NSNotification) -> () (TerminationRecovery.swift)
16 CoreFoundation 0x189d7eb10 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
17 CoreFoundation 0x189d7e214 _CFXRegistrationPost + 400
18 CoreFoundation 0x189d7df90 ___CFXNotificationPost_block_invoke + 60
19 CoreFoundation 0x189dedb8c -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1504
20 CoreFoundation 0x189cbfe64 _CFXNotificationPost + 376
21 Foundation 0x18a7f4e0c -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
22 UIKit 0x18ff1cd38 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4196
23 UIKit 0x18ff22808 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1656
24 UIKit 0x18ff37104 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3139 + 48
25 UIKit 0x18ff1f7ec -[UIApplication workspaceDidEndTransaction:] + 168
26 FrontBoardServices 0x18b9bb92c __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
27 FrontBoardServices 0x18b9bb798 -[FBSSerialQueue _performNext] + 176
28 FrontBoardServices 0x18b9bbb40 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
29 CoreFoundation 0x189d92b5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
30 CoreFoundation 0x189d924a4 __CFRunLoopDoSources0 + 524
31 CoreFoundation 0x189d900a4 __CFRunLoopRun + 804
32 CoreFoundation 0x189cbe2b8 CFRunLoopRunSpecific + 444
33 UIKit 0x18fd057b0 -[UIApplication _run] + 608
34 UIKit 0x18fd00534 UIApplicationMain + 208
35 rMove 0x100103b00 main (main.m:32)
36 libdispatch.dylib 0x188ca15b8 (Missing)
This line in the stack trace:
2 rMove 0x10022d320 globalinit_33_2CFFAAA7EF6073F07DB88164E80B793B_func11 (Utilities.swift:177)
Corresponds with this line in the code:
static let BACKEND_DB:FMDatabase = Database.getOpenedDb("mainIosDb")
My guess and hope is that there's some great information in that stack trace which points directly at the cause of this issue and I just don't know how to interpret it.
You have to open database with flags,
try belloe code it works for me
[self.database openWithFlags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FILEPROTECTION_NONE];
This is the crash log I got from Crashlytics:
Thread : Crashed: com.apple.main-thread
0 Trenìt! 0x1000b93e4 SearchHistoryProvider.getMostRecentStations(Int) -> [String] (SearchHistoryProvider.swift)
1 Trenìt! 0x10007985c specialized MasterViewController.onTouchedTextField(UITextField) -> () (MasterViewController.swift:265)
2 Trenìt! 0x100075414 #objc MasterViewController.onTouchedTextField(UITextField) -> () (MasterViewController.swift)
3 UIKit 0x186fa0ad0 -[UIApplication sendAction:to:from:forEvent:] + 100
4 UIKit 0x186fa0a4c -[UIControl sendAction:to:forEvent:] + 80
5 UIKit 0x186f88740 -[UIControl _sendActionsForEvents:withEvent:] + 436
6 UIKit 0x186fa9248 -[UIControl touchesBegan:withEvent:] + 400
7 UIKit 0x186f9fdc0 -[UIWindow _sendTouchesForEvent:] + 376
8 UIKit 0x186f98b08 -[UIWindow sendEvent:] + 784
9 UIKit 0x186f68f4c -[UIApplication sendEvent:] + 248
10 UIKit 0x186f67528 _UIApplicationHandleEventQueue + 6568
11 CoreFoundation 0x181dd5124 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
12 CoreFoundation 0x181dd4bb8 __CFRunLoopDoSources0 + 540
13 CoreFoundation 0x181dd28b8 __CFRunLoopRun + 724
14 CoreFoundation 0x181cfcd10 CFRunLoopRunSpecific + 384
15 GraphicsServices 0x1835e4088 GSEventRunModal + 180
16 UIKit 0x186fd1f70 UIApplicationMain + 204
17 Trenìt! 0x10009b2fc main (AppDelegate.swift:14)```
(edited)
and this is my code:
MasterViewController.swift:
263 func showRecentStations(textField: UITextField) {
264 textField.text = ""
265 suggestionStations = masterContainerManager!.homeController?.searchHistoryProvider?.getMostRecentStations(10)
266 updateStationsTable(textField)
267 }
SearchHistoryProvider.swift
func getMostRecentStations (maxSize : Int) -> [String] {
let stationsByOldestArray = getRecentStationsByOldest()
let stations = NSMutableOrderedSet()
for i in (0...(stationsByOldestArray.count-1)).reverse() {
stations.addObject(stationsByOldestArray[i].depStation)
if stations.count==maxSize {
return stations.array as! [String]
}
stations.addObject(stationsByOldestArray[i].arrStation)
if stations.count==maxSize {
return stations.array as! [String]
}
}
return stations.array as! [String]
}
Can anyone understand what's the crash about?
I found the bug:
in case stationsByOldestArray.count was 0
the for loop would have been
for i in (0...-1).reverse()
I fixed it by rewriting the loop as
for i in (0..<stationsByOldestArray.count).reverse()
However I think the Swift crash reports are often hopelessly unhelpful!