Sorting an array error with Swift

I am getting data from my server using AFNetworking

and I am sorting the json array like this:

func comparator(a: Dictionary, b: Dictionary) -> Bool {
    let first: String = a["type_name"] as String!
    let sec: String = b["type_name"] as String!
    if (first == sec) {
        let first_type: String = a["name"] as String!
        let sec_type: String = b["name"] as String!
        return first_type < sec_type
    }
    return first < sec
}
var initialArray = jsonDictionary["VALUES"] as Array<Dictionary<String, AnyObject>>
var docArray = sorted(initialArray, comparator)

      

This works PERFECTLY when I run the app on my iPhone in debug mode (compiled via xcode). But when I do it through Testflight, app store or adhoc deployment, it crashes. I tried to do some debugging with it and it turned out that sorting is a bug. Stack trace I get from adhoc and app store (using Appsee):

_TTSGVSs26UnsafeMutableBufferPointerGVSs10DictionarySSPSs9AnyObject___GS_GS0_SSPS1____Ss21MutableCollectionType_GVSs28UnsafeBufferPointerGeneratorGS0_SSPS1____GS3_GS0_SSPS1____Ss13GeneratorType_GS0_SSPS1____SiSiSs21RandomAccessIndexType_SiSiSs18_SignedIntegerType_SiSiSs33_BuiltinIntegerLiteralConvertible_SiSiSs16SignedNumberType_SiSiS7__Si_GS0_SSPS1______TFSs14_introSortImplUSs21MutableCollectionType_USs13GeneratorType__Ss21RandomAccessIndexType_Ss18_SignedIntegerType_Ss33_BuiltinIntegerLiteralConvertible_Ss16SignedNumberType_S3_____FTRQ_GVSs5RangeQQ_5Index_RFTQQQ_9Generator7ElementS8__SbSi_T_

      

When I remove the sort above by doing this:

var docArray = jsonDictionary["VALUES"] as Array<Dictionary<String, AnyObject>>

      

Adhoc app deployed fine. What is the reason for the above error? How is it that my sort is fine in debug mode, but not in any release mode of the application? I am absolutely stuck with this!

I have completely read Apple's documentation on this:

https://developer.apple.com/library/mac/documentation/General/Reference/SwiftStandardLibraryReference/Array.html

+3


source to share


1 answer


It seems to be a bug with Swift

, otherwise I don't know why it is. I used to have a function comparator

defined in a success block for AFNetworking

. I removed it from there and used it as a method for the class and fixed it somehow. I'm not sure why this is a fix, because I did similar things in other parts of my code and it worked independently.



0


source







All Articles