Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using NSPropertyListSerialization.propertyListWithData in swift

Tags:

swift

xcode6

ios8

Trying to use the code block below, but don't know how to get the options bit to work in the else clause, I keep getting 'NSPropertyListMutabilityOptions' is not convertible to 'NSPropertyListReadOptions'. But the Read options don't have MutableContainersWithLeaves that I need.

//if the file does not already exist
    if(appStatsData != nil) {
        appStats.setObject(NSNumber.numberWithInt(0), forKey:"RunCount")
        appStats.setObject("No Courses Viewed", forKey:"LastCourseViewed")
    }else {
        appStats = NSPropertyListSerialization.propertyListWithData(appStatsData, options:     NSPropertyListMutabilityOptions.MutableContainersAndLeaves, format: nil, error: &error)
    }
like image 999
Alicester4WonderlandPresident Avatar asked Aug 23 '14 02:08

Alicester4WonderlandPresident


1 Answers

The options parameter has the type NSPropertyListReadOptions which is a type alias for Int.

NSPropertyListMutabilityOptions is a RawOptionSetType with Uint as the underlying raw type.

Therefore you have to convert the option to an Int with

appStats = NSPropertyListSerialization.propertyListWithData(appStatsData,
    options:Int(NSPropertyListMutabilityOptions.MutableContainersAndLeaves.rawValue),
    format: nil, error: &error)
like image 156
Martin R Avatar answered Nov 14 '22 13:11

Martin R