Plist无法写入数据

时间:2017-08-02 07:10:16

标签: ios swift

下面我提到我的代码。我有一系列字典。这本词典包含多种词典,它们是字典类型。 当我尝试将此数组写入plist时,plist显示为空白。

请帮帮我。

var profileDATA:Dictionary! = [String:Any]()
var educationDATA = Array<Dictionary<String, Any>>()
var portfolioDATA:Array<Dictionary<String, Any>>? = Array()
var achievementDATA :Array<Dictionary<String, Any>>? = Array()
var skillDATA = Array<Any>()
var experianceDATA:Array<Dictionary<String, Any>>? = Array()
var templeteType: String!

func DataStoreForEachPDF(_ FileName:String)
{
    let filemgr = FileManager.default
    let folderpathforNormal: String = URL(fileURLWithPath: self.docDire).appendingPathComponent("Profile").path
    let userpath:String = URL(fileURLWithPath: folderpathforNormal).appendingPathComponent("UserData").path
    if !filemgr.fileExists(atPath: userpath)
    {
        try? filemgr.createDirectory(atPath: userpath, withIntermediateDirectories: false, attributes: nil)
    }

    let filepath:String = URL(fileURLWithPath: userpath).appendingPathComponent("user.plist").path
    var DataArray = Array<Dictionary<String, Any>>()
    let array = NSArray(contentsOfFile: filepath)
    if array != nil
    {
        DataArray = array as! Array
    }
    var UserDataDictionary = Dictionary<String, Any>()
    var str = ""
    let userdefault:UserDefaults = UserDefaults.standard
    if userdefault.bool(forKey: "fresher")
    {
        str = userdefault.string(forKey: "fresherdisc")!
        UserDataDictionary.updateValue(str , forKey: "experiancedata")
    }
    else
    {UserDataDictionary.updateValue(experianceDATA as Any, forKey: "experiancedata")}
    UserDataDictionary.updateValue(profileDATA, forKey: "profiledata")
    UserDataDictionary.updateValue(educationDATA, forKey: "educationdata")
    UserDataDictionary.updateValue(skillDATA, forKey: "skilldata")
    UserDataDictionary.updateValue(achievementDATA as Any, forKey: "achievementdata")
    UserDataDictionary.updateValue(portfolioDATA as Any, forKey: "portfoliodata")
    UserDataDictionary.updateValue(templeteType, forKey: "templetetype")
    var userDataMainDict = Dictionary<String ,Dictionary<String,Any>>()
    userDataMainDict.updateValue(userDataMainDict, forKey: FileName)
    if DataArray.count == 0
    {
        DataArray = [userDataMainDict]
    }
    else{DataArray.append(userDataMainDict)}
    print(DataArray)
    (DataArray as NSArray).write(toFile: filepath, atomically: true)
}

如果我的代码中有任何错误,请更新

0 个答案:

没有答案