我从服务器获取值并将它们存储到Coredata。问题是,当我从服务器获取数据并将它们存储在coredata中时,它表明我已经存储了我的值所有值.....
这些是我存储的数据:
[{
adName = Britannia;
adType = Video;
addescription = "Choco Muffills come with thick chocolate filling that will take you by surprise.";
clientImage = "http://api.weoneapp.com:8595/1464528609370.png";
clientName = Britannia;
endDate = "Just now";
entryId = 1478230186228;
likeFlag = 0;
mainImage = "";
newAdvertisement = 1;
noOfCount = 1367;
noOfLike = 2783;
seenAdvertisement = 0;
smilURL = "http://52.66.101.222:1935/vod/_definst_/1478230186228/smil:1478230186228.smil/playlist.m3u8";
sortDate = "2016-11-03T19:27:00.000Z";
startDate = "2016-11-03T19:27:00.000Z";
subTitle = "Britannia Cake Muffills";
thumbNail = "http://52.66.101.222:8595/video/1478230186228/1478230186228_thumbnail.png";
videoDownloadUrl = "http://52.66.101.222:8595/video/1478230186228/1478230186228_source.mp4";
}, {
adName = "Kwality Walls";
adType = Video;
addescription = "Paddle Pop Yummy Delicious Dessert - A delicious, colourful and yummy dessert ... Walls India \U00b7 Kulfeez from Kwality Walls India \U00b7";
clientImage = "http://api.weoneapp.com:8595/1464524885184.jpg";
clientName = "Kwality Walls";
endDate = "Just now";
entryId = 1478230623594;
likeFlag = 0;
mainImage = "";
newAdvertisement = 1;
noOfCount = 1281;
noOfLike = 2618;
seenAdvertisement = 0;
smilURL = "http://52.66.101.222:1935/vod/_definst_/1478230623594/smil:1478230623594.smil/playlist.m3u8";
sortDate = "2016-11-03T18:36:00.000Z";
startDate = "2016-11-03T18:36:00.000Z";
subTitle = "Paddle Pop Jiggly Jelly";
thumbNail = "http://52.66.101.222:8595/video/1478230623594/1478230623594_thumbnail.png";
videoDownloadUrl = "http://52.66.101.222:8595/video/1478230623594/1478230623594_source.mp4";
}, {
adName = "Cadbury Dairy Milk";
adType = Video;
addescription = "Your favourite chocolate is now more chocolatey.";
clientImage = "http://api.weoneapp.com:8595/1464017173884.jpg";
clientName = Cadbury;
endDate = "Just now";
entryId = 1478230473291;
likeFlag = 0;
mainImage = "";
newAdvertisement = 0;
noOfCount = 1310;
noOfLike = 2600;
seenAdvertisement = 1;
smilURL = "http://52.66.101.222:1935/vod/_definst_/1478230473291/smil:1478230473291.smil/playlist.m3u8";
sortDate = "2016-11-03T18:32:00.000Z";
startDate = "2016-11-03T18:32:00.000Z";
subTitle = "Cadbury Dairy Milk";
thumbNail = "http://52.66.101.222:8595/video/1478230473291/1478230473291_thumbnail.png";
videoDownloadUrl = "http://52.66.101.222:8595/video/1478230473291/1478230473291_source.mp4";
}]
现在,当我访问位于此位置的.sqlite文件夹时: / Users / Johnn / Library / Developer / CoreSimulator / Devices / 0DF66BFE-6076-45E9-8325-D61F1C738DFA / data / Containers / Data /Application/DC3F7B17-1172-4AE3-BC3B-217624C21AA5/Documents/AppCoreData.sqlite
只存储了两个值,我的最后一个条目值为空。
我不知道这背后的原因是什么,为什么我的最后一个数组值没有存储在数据库中......
我存储的值如下:
class func createInManagedObjectContext(nameOfAdvert: String, thumbnail: String, fileName: String, videoDownloadUrl: String, subTitle: String, adType: String, mainImage: String, noOfLike: NSNumber, entryId: String, likeFlag: Bool, startDate: String, endDate: String, noOfCount: NSNumber ,clientName: String, clientImage: String, adDesc: String, sortDate: String, newAdvertisement: Bool, seenAdvertisement: Bool) -> Tube {
let managedObjectContext = DataAccess.shared.managedObjectContext
let newItems = NSEntityDescription.insertNewObjectForEntityForName("Tube", inManagedObjectContext: managedObjectContext) as! Tube
do {
try managedObjectContext.save()
newItems.adName = nameOfAdvert
newItems.thumbNail = thumbnail
newItems.smilURL = fileName
newItems.videoDownloadUrl = videoDownloadUrl
newItems.subTitle = subTitle
newItems.adType = adType
newItems.mainImage = mainImage
newItems.noOfLike = noOfLike
newItems.entryId = entryId
newItems.likeFlag = likeFlag
newItems.startDate = startDate
newItems.endDate = endDate
newItems.noOfCount = noOfCount
newItems.clientImage = clientImage
newItems.clientName = clientName
newItems.addescription = adDesc
newItems.sortDate = sortDate
newItems.newAdvertisement = newAdvertisement
newItems.seenAdvertisement = seenAdvertisement
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
print("-----------------------------")
print(newItems)
return newItems
}
我不知道为什么所有数据都没有保存在coredata中。任何帮助将不胜感激。
提前致谢
答案 0 :(得分:5)
请写下此代码: - >
插入数据后写class func createInManagedObjectContext(nameOfAdvert: String, thumbnail: String, fileName: String, videoDownloadUrl: String, subTitle: String, adType: String, mainImage: String, noOfLike: NSNumber, entryId: String, likeFlag: Bool, startDate: String, endDate: String, noOfCount: NSNumber ,clientName: String, clientImage: String, adDesc: String, sortDate: String, newAdvertisement: Bool, seenAdvertisement: Bool) -> Tube {
let managedObjectContext = DataAccess.shared.managedObjectContext
let newItems = NSEntityDescription.insertNewObjectForEntityForName("Tube", inManagedObjectContext: managedObjectContext) as! Tube
newItems.adName = nameOfAdvert
newItems.thumbNail = thumbnail
newItems.smilURL = fileName
newItems.videoDownloadUrl = videoDownloadUrl
newItems.subTitle = subTitle
newItems.adType = adType
newItems.mainImage = mainImage
newItems.noOfLike = noOfLike
newItems.entryId = entryId
newItems.likeFlag = likeFlag
newItems.startDate = startDate
newItems.endDate = endDate
newItems.noOfCount = noOfCount
newItems.clientImage = clientImage
newItems.clientName = clientName
newItems.addescription = adDesc
newItems.sortDate = sortDate
newItems.newAdvertisement = newAdvertisement
newItems.seenAdvertisement = seenAdvertisement
do {
try managedObjectContext.save()
} catch let error as NSError {
print("Could not save \(error), \(error.userInfo)")
}
print("-----------------------------")
print(newItems)
return newItems
。
{{1}}
}