Initializing realm globally causing a crash - ios

I have a swift app with realm integrated to it. I am declaring the realm globally in the AppDelegate.swift as shown below in the code. When I execute this application, My app runs fine on the devices and even in the test mode.
Issue:
After my app submission, the Apple review board rejected app and the symbolicated crash logs pointed the initialisation of the realm.
Below is the code, what am I possibly doing wrong?
import UIKit
import CoreData
import Firebase
import UserNotifications
import Fabric
import RealmSwift
var uiRealm = try! Realm()
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
var window: UIWindow?
let gcmMessageIDKey = "gcm.message_id"
var tokenExists = false
let imageDb = DigitalFingerprint()
var uid: String!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
#if DEVELOPMENT
print("Development Mode Started")
let filePath = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist")
guard let fileopts = FirebaseOptions.init(contentsOfFile: filePath!)
else {
fatalError("Couldn't load config file")
}
FirebaseApp.configure(options: fileopts)
#else
print("Production Mode Started")
FirebaseApp.configure()
#endif
Auth.auth().addStateDidChangeListener { (auth, user) in
if (user != nil) {
print("User is there")
self.uid = KeychainWrapper.standard.string(forKey: KEY_UID)
} else {
print("user signed out")
DB_URL.removeAllObservers()
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "starts") as? BootVC
var topRootViewController: UIViewController = (UIApplication.shared.keyWindow?.rootViewController)!
while((topRootViewController.presentedViewController) != nil){
topRootViewController = topRootViewController.presentedViewController!
}
topRootViewController.present(vc!, animated: true, completion: nil)
}
}
}
if uid != nil {
checkforAccess()
}
return true
}
Following is the Real object, DigitalFingerprint.swift
import Foundation
import RealmSwift
import UIKit
class DigitalFingerprint: Object {
#objc dynamic var imageData: Data? = nil
#objc dynamic var fid : String? = nil
#objc dynamic var uid : String? = nil
override static func primaryKey() -> String {
return "uid"
}
}
extension DigitalFingerprint {
func writeToRealm(){
try! uiRealm.write {
uiRealm.add(self, update: true)
}
}
func DeleteFromRealm(object: Results<DigitalFingerprint>){
try! uiRealm.write {
uiRealm.delete(object)
}
}
}
crash Logs received by apple review board. :
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
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x00000001830142e8 __pthread_kill + 8
1 libsystem_pthread.dylib 0x00000001831292f8 pthread_kill$VARIANT$mp + 396
2 libsystem_c.dylib 0x0000000182f83060 __abort + 152
3 libsystem_c.dylib 0x0000000182f82fc8 __abort + 0
4 libc++abi.dylib 0x000000018271f068 __cxa_bad_cast + 0
5 libc++abi.dylib 0x000000018271f1f8 default_terminate_handler+ 8696 () + 280
6 libobjc.A.dylib 0x0000000182748820 _objc_terminate+ 34848 () + 140
7 SpotMi 0x0000000100dc7d78 CLSTerminateHandler() + 1260920 (CLSException.mm:314)
8 libc++abi.dylib 0x000000018273754c std::__terminate(void (*)+ 107852 ()) + 16
9 libc++abi.dylib 0x00000001827375b8 std::terminate+ 107960 () + 60
10 Realm 0x0000000101f94a00 realm::Realm::open_with_config(realm::Realm::Config const&, std::__1::unique_ptr<realm::Replication, std::__1::default_delete<realm::Replication> >&, std::__1::unique_ptr<realm::SharedGroup, std::__1::default_delete<realm::SharedGroup> >&, std::__1::unique_ptr<realm::Group, std::__1::default_delete<realm::Group> >&, realm::Realm*) + 985600 (memory:3006)
11 Realm 0x0000000101f944e0 realm::Realm::Realm(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>) + 984288 (shared_realm.cpp:55)
12 Realm 0x0000000101ed9658 realm::Realm::make_shared_realm(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>)::make_shared_enabler::make_shared_enabler(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>) + 218712 (shared_realm.hpp:304)
13 Realm 0x0000000101ed94cc std::__1::shared_ptr<realm::Realm::make_shared_realm(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>)::make_shared_enabler> std::__1::shared_ptr<realm::Realm::make_shared_realm(realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator>)::make_shared_enabler>::make_shared<realm::Realm::Config, std::__1::shared_ptr<realm::_impl::RealmCoordinator> >(realm::Realm::Config&&, std::__1::shared_ptr<realm::_impl::RealmCoordinator>&&) + 218316 (memory:2172)
14 Realm 0x0000000101ed56a4 realm::_impl::RealmCoordinator::get_realm(realm::Realm::Config) + 202404 (realm_coordinator.cpp:229)
15 Realm 0x0000000101f965f0 realm::Realm::get_shared_realm(realm::Realm::Config) + 992752 (shared_realm.cpp:250)
16 Realm 0x0000000101f7016c +[RLMRealm realmWithConfiguration:error:] + 835948 (RLMRealm.mm:400)
17 RealmSwift 0x00000001023911e4 Realm.init() + 152036 (Realm.swift:0)
18 RealmSwift 0x0000000102391178 Realm.__allocating_init() + 151928 (Realm.swift:0)
19 SpotMi 0x0000000100c9be14 globalinit_33_E3853139275E4567E078AE3BFE0165A3_func0 + 32276 (AppDelegate.swift:23)
20 libdispatch.dylib 0x0000000182e7ea14 _dispatch_client_callout + 16
21 libdispatch.dylib 0x0000000182e82240 dispatch_once_f$VARIANT$mp + 60
22 SpotMi 0x0000000100cc2254 FeedVC.viewDidLoad() + 189012 (FeedVC.swift:84)
23 SpotMi 0x0000000100cc2650 #objc FeedVC.viewDidLoad() + 190032 (FeedVC.swift:0)
24 UIKit 0x000000018c9e3ae8 -[UIViewController loadViewIfRequired] + 1040
25 UIKit 0x000000018c9e36c0 -[UIViewController view] + 28
26 UIKit 0x000000018c9ea28c -[UIWindow addRootViewControllerViewIfPossible] + 136
27 UIKit 0x000000018c9e74ec -[UIWindow _setHidden:forced:] + 272
28 UIKit 0x000000018ca563a0 -[UIWindow makeKeyAndVisible] + 48
29 UIKit 0x000000018cc43d10 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3620
30 UIKit 0x000000018cc48aa8 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1712
31 UIKit 0x000000018cee42d4 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 800
32 UIKit 0x000000018d1bc12c +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 160
33 UIKit 0x000000018cee3f38 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 252
34 UIKit 0x000000018cee4798 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 732
35 UIKit 0x000000018d6697d0 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 260
36 UIKit 0x000000018d669674 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 448
37 UIKit 0x000000018d3d72dc __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 220
38 UIKit 0x000000018d5703dc _performActionsWithDelayForTransitionContext + 112
39 UIKit 0x000000018d3d718c -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 252
40 UIKit 0x000000018d1bb78c -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 364
41 UIKit 0x000000018cc471ec -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 540
42 UIKit 0x000000018d05cde8 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 364
43 FrontBoardServices 0x0000000185bc61f0 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 364
44 FrontBoardServices 0x0000000185bceaf8 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 224
45 libdispatch.dylib 0x0000000182e7ea14 _dispatch_client_callout + 16
46 libdispatch.dylib 0x0000000182e86200 _dispatch_block_invoke_direct$VARIANT$mp + 288
47 FrontBoardServices 0x0000000185bfa7f8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
48 FrontBoardServices 0x0000000185bfa49c -[FBSSerialQueue _performNext] + 404
49 FrontBoardServices 0x0000000185bfaa38 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
50 CoreFoundation 0x00000001834aa97c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
51 CoreFoundation 0x00000001834aa8fc __CFRunLoopDoSource0 + 88
52 CoreFoundation 0x00000001834aa184 __CFRunLoopDoSources0 + 204
53 CoreFoundation 0x00000001834a7d5c __CFRunLoopRun + 1048
54 CoreFoundation 0x00000001833c7e58 CFRunLoopRunSpecific + 436
55 GraphicsServices 0x0000000185274f84 GSEventRunModal + 100
56 UIKit 0x000000018ca4767c UIApplicationMain + 236
57 SpotMi 0x0000000100c99b4c main + 23372 (SurpriseCell.swift:26)
58 libdyld.dylib 0x0000000182ee456c start + 4
And I am calling this function also in my initialviewcontroller(Feedvc), in the viewDidAppear()
The flow of my program is
1.load feedvc
if the user is nil
Go to the bootVc(thats called from app delegate)
Again what exactly am i doing wrong?
Also, will just declaring a variable of type realm globally and then initialzing the variable in didFinishLaunching() be a better option?
Thanks!

Well, it is not a good idea to create variables outside the class. Try to create
var uiRealm = try! Realm()
inside the AppDelegate class. And use (UIApplication.shared.delegate as! AppDelegate).uiRealm in other classes.

Related

specialized UIViewController calling some method crashing iOS Swift

I am unable to replicate this issue, how to replicate the following fabric crash ?
Is there a way to open this crash in xcode (Importing crash into xcode)
Crashed: com.apple.main-thread
0 ABCC 0x10092d0c4 specialized ABCViewController.signInBtnPressed(UIButton) -> ()(ABCViewController.swift:178)
1 ABCC 0x10092a520 #objc ABCViewController.unwind(UIStoryboardSegue) -> () + 3152641510
2 UIKit 0x18aced64c -[UIApplication sendAction:to:from:forEvent:] + 86
3 UIKit 0x18ae0e870 -[UIControl sendAction:to:forEvent:] + 52
4 UIKit 0x18acf3700 -[UIControl _sendActionsForEvents:withEvent:] + 120
5 UIKit 0x18ae291a8 -[UIControl touchesEnded:withEvent:] + 492
6 UIKit 0x18b2ceee8 _UIGestureEnvironmentSortAndSendDelayedTouches + 4340
7 UIKit 0x18b2cbc60 _UIGestureEnvironmentUpdate + 1236
8 UIKit 0x18ad664d8 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 404
9 UIKit 0x18ad66010 -[UIGestureEnvironment _updateGesturesForEvent:window:] + 276
10 UIKit 0x18ad65874 -[UIWindow sendEvent:] + 3132
11 UIKit 0x18ad641d0 -[UIApplication sendEvent:] + 340
12 UIKit 0x18b545d1c __dispatchPreprocessedEventFromEventQueue + 2340
13 UIKit 0x18b5482c8 __handleEventQueueInternal + 4744
14 CoreFoundation 0x180f27404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
15 CoreFoundation 0x180f26c2c __CFRunLoopDoSources0 + 276
16 CoreFoundation 0x180f2479c __CFRunLoopRun + 1204
17 CoreFoundation 0x180e44da8 CFRunLoopRunSpecific + 552
18 GraphicsServices 0x182e2a020 GSEventRunModal + 100
19 UIKit 0x18ae64758 UIApplicationMain + 236
20 ABCC 0x1007b28c4 main (main.m:20)
21 libdyld.dylib 0x1808d5fc0 start + 4
Here is the code for the action that is crashing.
#IBAction func signInBtnPressed(_ sender: UIButton) {
sender.isUserInteractionEnabled = false
guard let employees = UserService.shared.employees, let name = employees.names?[sender.tag] else {
sender.isUserInteractionEnabled = true // crashing here
return
}
// perform task
sender.isUserInteractionEnabled = true
}

Scope for Crashed: com.apple.main-thread EXC_BREAKPOINT on ViewController Initialisation

This is my stack trace on fabric:
Crashed: com.apple.main-thread.
EXC_BREAKPOINT 0x0000000100b9ac64
Crashed: com.apple.main-thread
0 ABC 0x100b9ac64 specialized GameItemViewController.init(coder : NSCoder) -> GameItemViewController? (GameItemViewController.swift:5)
1 ABC 0x100b952f0 #objc GameItemViewController.init(coder : NSCoder) -> GameItemViewController? (GameItemViewController.swift)
2 UIKit 0x18cb6dedc -[UIClassSwapper initWithCoder:] + 248
3 UIKit 0x18cccf628 UINibDecoderDecodeObjectForValue + 688
4 UIKit 0x18cccf360 -[UINibDecoder decodeObjectForKey:] + 312
5 UIKit 0x18cb6db84 -[UIRuntimeConnection initWithCoder:] + 188
6 UIKit 0x18cb6e31c -[UIRuntimeEventConnection initWithCoder:] + 64
7 UIKit 0x18cccf628 UINibDecoderDecodeObjectForValue + 688
8 UIKit 0x18cccf7a0 UINibDecoderDecodeObjectForValue + 1064
9 UIKit 0x18cccf360 -[UINibDecoder decodeObjectForKey:] + 312
10 UIKit 0x18cb6ced4 -[UINib instantiateWithOwner:options:] + 1164
11 UIKit 0x18ce79d88 -[UIStoryboard instantiateViewControllerWithIdentifier:] + 196
12 UIKit 0x18ce86610 -[UIStoryboardSegueTemplate instantiateOrFindDestinationViewControllerWithSender:] + 92
13 UIKit 0x18ce8686c -[UIStoryboardSegueTemplate _perform:] + 56
14 UIKit 0x18c99f4d0 -[UIViewController performSegueWithIdentifier:sender:] + 108
15 ABC 0x100b66788 GamesViewController.gameTapped(Any) -> () (GamesViewController.swift:225)
16 ABC 0x100b66a84 #objc GamesViewController.gameTapped(Any) -> () + 4300515972
17 UIKit 0x18c65a6c8 -[UIApplication sendAction:to:from:forEvent:] + 96
18 UIKit 0x18c77b8a4 -[UIControl sendAction:to:forEvent:] + 80
19 UIKit 0x18c66077c -[UIControl _sendActionsForEvents:withEvent:] + 440
20 UIKit 0x18c7961dc -[UIControl touchesEnded:withEvent:] + 572
21 UIKit 0x18c6dda48 -[UIWindow _sendTouchesForEvent:] + 2428
22 UIKit 0x18c6d28f8 -[UIWindow sendEvent:] + 3160
23 UIKit 0x18c6d1238 -[UIApplication sendEvent:] + 340
24 UIKit 0x18ceb2c0c __dispatchPreprocessedEventFromEventQueue + 2340
25 UIKit 0x18ceb51b8 __handleEventQueueInternal + 4744
26 UIKit 0x18ceae258 __handleHIDEventFetcherDrain + 152
27 CoreFoundation 0x1828d3404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
28 CoreFoundation 0x1828d2c2c __CFRunLoopDoSources0 + 276
29 CoreFoundation 0x1828d079c __CFRunLoopRun + 1204
30 CoreFoundation 0x1827f0da8 CFRunLoopRunSpecific + 552
31 GraphicsServices 0x1847d3020 GSEventRunModal + 100
32 UIKit 0x18c7d178c UIApplicationMain + 236
33 ABC 0x100b28f60 main (GamesViewModel.swift:11)
34 libdyld.dylib 0x182281fc0 start + 4
The crash occurs when i segue between GamesViewController and GameItemViewController.
I don't have any asynchronous task in my IBAction logic where i start the actual segue. I just check for 3 different booleans and start different ViewControllers respectively.
#IBAction func gameTapped(_ sender: Any) {
if x {
performSegue(withIdentifier: "x", sender: nil)
} else if y {
performSegue(withIdentifier: "y", sender: nil)
} else {
performSegue(withIdentifier: "showGameItem", sender: nil)
}
}
This line which the crash points to (GameItemViewController.swift:5) is the view controller declaration like so:
import UIKit
import RxSwift
import RxCocoa
class GameItemViewController: UIViewController {
}
Also i have NOT overridden the
init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?
OR
required init?(coder aDecoder: NSCoder)
I'm not able to recreate this, however I can see logs on crashlytics with multiple devices having the issue.

Crash in libswiftCore.dylib _assertionFailed, no idea what is causing this

Ok, so I understand that this question is a bit broad, but I do not know how to proceed.
So this is what my crash looks like from fabric (I have not been able to reproduce this, but I'm getting alot of crashes like this)
Crashed: com.apple.main-thread
0 libswiftCore.dylib 0x101085cb8 _assertionFailed(StaticString, String, StaticString, UInt, flags : UInt32) -> Never (__hidden#16085_:167)
1 libswiftCore.dylib 0x1010a5a70 _hidden#1062_ + 504
2 libswiftCore.dylib 0x1010a5878 swift_errorInMain + 26
3 MYAPPPPPP 0x10006da44 specialized static FFBaseApiService.accessTokenGetString.getter (FFBaseApiService.swift)
4 libdispatch.dylib 0x191a9a1bc _dispatch_client_callout + 16
5 libdispatch.dylib 0x191a9afb0 dispatch_once_f + 56
6 MYAPPPPPP 0x100105208 specialized FFAppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (FFAppDelegate.swift:62)
7 MYAPPPPPP 0x100101b70 #objc FFAppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [UIApplicationLaunchOptionsKey : Any]?) -> Bool (FFAppDelegate.swift)
8 UIKit 0x198b386a4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 400
9 UIKit 0x198d48a98 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3524
10 UIKit 0x198d4e808 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1656
11 UIKit 0x198d63104 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke.3139 + 48
12 UIKit 0x198d4b7ec -[UIApplication workspaceDidEndTransaction:] + 168
13 FrontBoardServices 0x1947e792c __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 36
14 FrontBoardServices 0x1947e7798 -[FBSSerialQueue _performNext] + 176
15 FrontBoardServices 0x1947e7b40 -[FBSSerialQueue _performNextFromRunLoopSource] + 56
16 CoreFoundation 0x192bbeb5c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
17 CoreFoundation 0x192bbe4a4 __CFRunLoopDoSources0 + 524
18 CoreFoundation 0x192bbc0a4 __CFRunLoopRun + 804
19 CoreFoundation 0x192aea2b8 CFRunLoopRunSpecific + 444
20 UIKit 0x198b317b0 -[UIApplication _run] + 608
21 UIKit 0x198b2c534 UIApplicationMain + 208
22 MYAPPPPPP 0x100059138 main (UserDefaultsWrapper.swift:21)
23 libdispatch.dylib 0x191acd5b8 (Missing)
To me it seems as if it's this row that is crashing on appdelegate startup:
specialized static FFBaseApiService.accessTokenGetString.getter (FFBaseApiService.swift)
This is the code for this:
class var accessTokenGetString : String {
return "?accessToken=\(currentUserAccessToken)"
}
class var currentUserAccessToken : String {
return FFUserManager.sharedInstance.getUserAccessToken()
}
Also, I am using realm, and the getUserAccessToken looks like this:
func getUserAccessToken() -> String {
if let user = user, let accessToken = user.accessToken {
return accessToken
}
else {
print("Returning empty access token")
return ""
}
}
Where the user property is fetched like this:
private var user : FFUser? {
return realm.objects(FFUser.self).first
}
I have NO IDEA whatsoever what could be wrong here. Any takers?

Swift crash reports don't make sense to me

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!

EXC_BREAKPOINT crash when I am trying to create a rematch using game center

I am getting this crash report from my users. I am not able to reproduce it so only few devices are having this issue.
Thread : Crashed: com.apple.main-thread
0 MY_PROJECT 0x00089fb8 static MY_PROJECT.GCHelper.rematch (MY_PROJECT.GCHelper.Type)(Swift.ImplicitlyUnwrappedOptional) -> () (GCHelper.swift:156)
1 libobjc.A.dylib 0x37624a37 objc_object::sidetable_retain() + 82
2 MY_PROJECT 0x000403f0 MY_PROJECT.GameScene.ButtonFunction (MY_PROJECT.GameScene)() -> () (GameScene.swift:727)
3 MY_PROJECT 0x00052ae0 function signature specialization of MY_PROJECT.GameScene.touchesEnded (MY_PROJECT.GameScene)(Swift.Set, withEvent : ObjectiveC.UIEvent) -> () (GameScene.swift:355)
4 MY_PROJECT 0x0003d7ac #objc MY_PROJECT.GameScene.touchesEnded (MY_PROJECT.GameScene)(Swift.Set, withEvent : ObjectiveC.UIEvent) -> () (GameScene.swift)
5 SpriteKit 0x2c668755 -[SKView touchesEnded:withEvent:] + 896
6 UIKit 0x2c7fc133 -[UIWindow _sendTouchesForEvent:] + 522
7 UIKit 0x2c7f5a41 -[UIWindow sendEvent:] + 540
8 UIKit 0x2c7cbc05 -[UIApplication sendEvent:] + 196
9 UIKit 0x2ca4231f _UIApplicationHandleEventFromQueueEvent + 14538
10 UIKit 0x2c7ca607 _UIApplicationHandleEventQueue + 1350
11 CoreFoundation 0x2915722f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
12 CoreFoundation 0x29156643 __CFRunLoopDoSources0 + 222
13 CoreFoundation 0x29154cc1 __CFRunLoopRun + 768
14 CoreFoundation 0x290a09a1 CFRunLoopRunSpecific + 476
15 CoreFoundation 0x290a07b3 CFRunLoopRunInMode + 106
16 GraphicsServices 0x3085f1a9 GSEventRunModal + 136
17 UIKit 0x2c82b695 UIApplicationMain + 1440
18 MY_PROJECT 0x00086790 main (AppDelegate.swift:16)
19 libdyld.dylib 0x37bb2aaf start + 2
Below is my rematch function from GCHelper class.
class func rematch(match:GKTurnBasedMatch!){
GCHelper.sharedInstance.rematch(match)
}
func rematch(match:GKTurnBasedMatch!){
match.rematchWithCompletionHandler({ (mMatch:GKTurnBasedMatch!, error:NSError!) -> Void in
if(error != nil){
println("\(error.description)")
} else{
println("rematch")
for var i = 0; i < mMatch.participants.count; i++ {
let participants = mMatch.participants as NSArray
let part = participants.objectAtIndex(i) as! GKTurnBasedParticipant
println("part \(i) \(part.description)")
if let playerID = part.playerID {
if(part.playerID != GKLocalPlayer.localPlayer().playerID){
self.opponentName = part.player.displayName
}
} else{
self.opponentName = "Opponent"
}
// println("participant name is \(part.playerID.)")
}
println("participant name is \(self.opponentName)")
self.delegate?.enterRematch(match,opponentName: self.opponentName)
}
})
}
And this is how I call rematch in my GameScene class.
GCHelper.rematch(self.currentTurnBasedMatch)
I don't even know at which line exactly the crash is happening. Anyone have any ideas?

Resources