Encoding an array of CLLocation in Swift crashes the compiler?

Samm Bennett

I have a Swift class that seems to work fine, except when I try to implement NSCoding. The line that seems to be giving me an issue is:

        aCoder.encodeObject(runSamples, forKey: "runSamples")

If I comment this line out, everything compiles fine. However, uncommenting it in Xcode results in:

Bitcast requires both operands to be pointer or neither %201 = bitcast i32 %200 to %objc_object*, !dbg !241 LLVM ERROR: Broken function found, compilation aborted! Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1

Uncommenting the line Playground just causes the app to crash.

I assume this is a compiler issue, but I want to see if there was something I'm obviously missing before reporting to Apple.

Full class:

class RunRecord: NSObject {
    let startDate: NSDate
    var endDate: NSDate?
    var runSamples: CLLocation[]

    var currentSpeed: CLLocationDistance {
    return self.runSamples[runSamples.endIndex - 1].speed
    }

    init(startDate: NSDate) {
        self.startDate = startDate
        self.runSamples = CLLocation[]()
        super.init()
    }

    init(coder aDecoder: NSCoder!) {
        startDate = aDecoder.decodeObjectForKey("startDate") as NSDate
        endDate = aDecoder.decodeObjectForKey("endDate") as? NSDate
        runSamples = aDecoder.decodeObjectForKey("runSamples") as CLLocation[]
    }

    func encodeWithCoder(aCoder: NSCoder!) {
        aCoder.encodeObject(startDate, forKey: "startDate")
        aCoder.encodeObject(endDate, forKey: "endDate")
        aCoder.encodeObject(runSamples, forKey: "runSamples")
    }

    func addSample(sample: CLLocation) {
        runSamples.append(sample)
    }
}
Samm Bennett

Looks like the problem is that the Swift array was being automatically bridged to Objective-C. This fixes the issue:

aCoder.encodeObject(runSamples.bridgeToObjectiveC(), forKey: "runSamples")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CLLocation Manager in Swift to get Location of User

From Dev

@IBAction crashes app in Swift

From Dev

@objc protocol crashes the swift compiler

From Dev

Swift: Cast from Interface type array to Object array crashes

From Dev

Swift Compiler Error when accessing array - Exit code 254

From Dev

CLLocation distanceFromLocation (in Swift?)

From Dev

Bubble sorting an array in Swift, compiler error on swap

From Dev

Saving Swift CLLocation in CoreData

From Dev

put CLLocationCoordinate2D into CLLocation for Swift

From Dev

Calculating bearing between two CLLocation points in Swift

From Dev

Swift 1.2 crashes with .lowercaseString

From Dev

Initialize a CLLocation object in swift with latitude and longitude

From Dev

Swift compiler crashes on switch statement, need workaround

From Dev

In Swift, can I detect if a CLLocation is valid or not?

From Dev

Swift and NSCoding: Encoding an array of objects conforming to a class-only protocol

From Dev

Calculate travel time CLLocation Swift

From Dev

Compiler crashes on generic lambda

From Dev

How can I get the CLLocation of a photo selected from UIImagePickerController in Swift?

From Dev

@objc protocol crashes the swift compiler

From Dev

Swift: Cast from Interface type array to Object array crashes

From Dev

Custom Encoding with NSData, initializes but crashes

From Dev

How do I convert an NSNumber to a CLLocation in Swift

From Dev

Covert CLLocation to PFGeoPoint with Swift

From Dev

Objective-C calling parameterized Swift method crashes Swift compiler

From Dev

Calculate travel time CLLocation Swift

From Dev

Displaying CLLocation in label Xcode 7 Swift 2

From Dev

Swift 3.0 array "contains" argument compiler error

From Dev

Trying to update CLLocation if NSUserDefault Exists in Swift

From Dev

What's the best approach to sharing device CLLocation between ViewControllers in Swift?

Related Related

  1. 1

    CLLocation Manager in Swift to get Location of User

  2. 2

    @IBAction crashes app in Swift

  3. 3

    @objc protocol crashes the swift compiler

  4. 4

    Swift: Cast from Interface type array to Object array crashes

  5. 5

    Swift Compiler Error when accessing array - Exit code 254

  6. 6

    CLLocation distanceFromLocation (in Swift?)

  7. 7

    Bubble sorting an array in Swift, compiler error on swap

  8. 8

    Saving Swift CLLocation in CoreData

  9. 9

    put CLLocationCoordinate2D into CLLocation for Swift

  10. 10

    Calculating bearing between two CLLocation points in Swift

  11. 11

    Swift 1.2 crashes with .lowercaseString

  12. 12

    Initialize a CLLocation object in swift with latitude and longitude

  13. 13

    Swift compiler crashes on switch statement, need workaround

  14. 14

    In Swift, can I detect if a CLLocation is valid or not?

  15. 15

    Swift and NSCoding: Encoding an array of objects conforming to a class-only protocol

  16. 16

    Calculate travel time CLLocation Swift

  17. 17

    Compiler crashes on generic lambda

  18. 18

    How can I get the CLLocation of a photo selected from UIImagePickerController in Swift?

  19. 19

    @objc protocol crashes the swift compiler

  20. 20

    Swift: Cast from Interface type array to Object array crashes

  21. 21

    Custom Encoding with NSData, initializes but crashes

  22. 22

    How do I convert an NSNumber to a CLLocation in Swift

  23. 23

    Covert CLLocation to PFGeoPoint with Swift

  24. 24

    Objective-C calling parameterized Swift method crashes Swift compiler

  25. 25

    Calculate travel time CLLocation Swift

  26. 26

    Displaying CLLocation in label Xcode 7 Swift 2

  27. 27

    Swift 3.0 array "contains" argument compiler error

  28. 28

    Trying to update CLLocation if NSUserDefault Exists in Swift

  29. 29

    What's the best approach to sharing device CLLocation between ViewControllers in Swift?

HotTag

Archive