CoreData object to JSON in Swift 3

后端 未结 4 558
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 06:49

I\'m struggling to get my CoreData objects into JSON so that I can use it to send to a web server.

This is how I currently fetch my objects from CoreData:



        
4条回答
  •  一生所求
    2021-01-01 07:05

    If you want you can get the results in dictionary format from core data using below :

    let fetchRequest = NSFetchRequest(entityName:"Record")
    fetchRequest.resultType = .dictionaryResultType
    do {
        records = try context.fetch(fetchRequest)
    } catch {
        print("Error fetching data from CoreData")
    }
    

提交回复
热议问题