7

I'm new to Swift programming, Recently I have implemented spotlight search for my app with Swift. Everything is working well and good however I"m getting few crash reports nowadays and I have no clue what is "Partial apply" and why it is crashing. As I'm unable to simulate it locally I"m trying to solve it by using crash logs. Following is the crash report...

Thread : Crashed: com.apple.root.default-qos
0  AppName                        0x1076d4 partial apply for static spotLightSearchManager.(indexAllItem in _03019F3D5642F39F2DF678310DF7E384)() -> () (spotLightSearchManager.swift:77)
1  AppName                        0x10761c partial apply for static spotLightSearchManager.(indexAllItem in _03019F3D5642F39F2DF678310DF7E384)() -> () (spotLightSearchManager.swift:73)
2  AppName                        0x107730 partial apply for thunk (spotLightSearchManager.swift)
3  AppName                        0x107808 partial apply for static spotLightSearchManager.(clearAllItem(spotLightSearchManager.Type) -> (OnCompletion : () -> ()!) -> ()).(closure #1) (spotLightSearchManager.swift:85)
4  CoreSpotlight                  0x2ae7ce0d __45-[CSSearchableIndexRequest _finishWithError:]_block_invoke + 20
5  libdispatch.dylib              0x2492fdd7 _dispatch_call_block_and_release + 10
6  libdispatch.dylib              0x2493b7b9 _dispatch_root_queue_drain + 1572
7  libdispatch.dylib              0x2493b193 _dispatch_worker_thread3 + 94
8  libsystem_pthread.dylib        0x24ac8e0d _pthread_wqthread + 1024
9  libsystem_pthread.dylib        0x24ac89fc start_wqthread + 8

I'm trying to reindex search item during app launch time.

 static func reIndexAllItem () {

        if #available(iOS 9.0, *) {

            clearAllItem(OnCompletion: indexAllItem)


        } else {
            // Fallback on earlier versions
            APLog("SpotLight index not added for older versions")
        }
    }
}

static private func indexAllItem () {

    for dataItem in APAuthUrlDataSource.sharedInstance().accountArray { // Crash logs points to this line.

        addSearchIndexForItem(dataItem as! APAuthUrlDataItm)
    }
} // Line number 77

static func clearAllItem (OnCompletion completion : (()-> Void)!) {

        if #available(iOS 9.0, *) {
            CSSearchableIndex.defaultSearchableIndex().deleteAllSearchableItemsWithCompletionHandler { (error) -> Void in
                // On completion.
                APLog("successfully cleared all index in spotlight search")
                **completion()** //Line number 85
            }
        } else {
            // Fallback on earlier versions
            APLog("SpotLight index not cleared for older versions")
        }
}

Note: reindexAlltem is getting called from didFinishLaunchingWithOptions method.

Any help would really appreciated, Thanks in Advance.

Feroz
  • 699
  • 5
  • 17
  • 25

1 Answers1

0

It seems that the cast to APAuthUrlDataItm fails. I assume that accountArray is not explicitly of type [APAuthUrlDataItm] otherwise why would you need that cast?

Consider this code:

    for dataItem in accountArray {
        if let item = dataItem as? APAuthUrlDataItm {
            addSearchIndexForItem(item)
        }
    }
Darko
  • 9,655
  • 9
  • 36
  • 48
  • But in such case, it should always fail right? I"m unable to simulate this crash on my side. – Feroz Dec 13 '15 at 13:25
  • Which type has the array? – Darko Dec 13 '15 at 13:27
  • Array has APAuthUrlDataItm items for sure. Moreover xcode crash logs points to this line "for dataItem in APAuthUrlDataSource.sharedInstance().accountArray {" – Feroz Dec 13 '15 at 13:29
  • 1
    Any idea what partial apply means? I haven't seen this kind of crash in ObjC. – Feroz Dec 13 '15 at 13:39
  • No. What could be wrong with this line? What about the sharedInstance? Please show the code. – Darko Dec 13 '15 at 13:40
  • APAuthUrlDataSource.sharedInstance() return a singleton object. – Feroz Dec 13 '15 at 13:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97764/discussion-between-feroz-mohideen-and-darko). – Feroz Dec 13 '15 at 13:47
  • + (APAuthUrlDataSource*) sharedInstance { if (!urlDataSource) { urlDataSource = [[APAuthUrlDataSource alloc] init]; } return urlDataSource; } static APAuthUrlDataSource *urlDataSource; I doubt it could be threading issue? – Feroz Dec 13 '15 at 13:51