How can I write/read log files of type JSON or CSV with Swift?

hey guys,


I am a newbie in xCode and Swift and I am currently struggling with implementing a solution for log captured location data to a JSON-File or CSV-File.


I have a collection of objects and I want to save this data to a log file.


The following code shows the structure of an object which I want to log.


class LocationLogData
{
    var timeStamp:     NSDate
    var location:      CLLocation
    var speed:         CLLocationSpeed
    var verticalAcc:   CLLocationAccuracy
    var horizontalAcc: CLLocationAccuracy
    var direction:     CLLocationDirection
    var distanceFromPreviousLocation : CLLocationDistance
    var locationName:  String?
   
    init(timeStamp:NSDate, location:CLLocation, speed:CLLocationSpeed, verticalAcc:CLLocationAccuracy, horizontalAcc:CLLocationAccuracy, direction:CLLocationDirection, distanceFromPreviousLocation:CLLocationDistance)
    {
        self.timeStamp      = timeStamp
        self.location       = location
        self.speed          = speed
        self.verticalAcc    = verticalAcc
        self.horizontalAcc  = horizontalAcc
        self.direction      = direction
        self.distanceFromPreviousLocation = distanceFromPreviousLocation
    }
   
    convenience init ()
    {
        self.init(timeStamp:NSDate.new(), location: CLLocation(), speed:0, verticalAcc:0, horizontalAcc:0, direction:0, distanceFromPreviousLocation:0)
    }
   
}


Can anyone help me and show me a sample code of how I can do this?


Thank you very much for your support

Regards

numb88

How can I write/read log files of type JSON or CSV with Swift?
 
 
Q