gpt4 book ai didi

ios - Swift CoreData 到 UICollectionView

转载 作者:行者123 更新时间:2023-11-30 12:41:51 30 4
gpt4 key购买 nike

这是我的代码: 导入 UIKit导入核心数据

class WeekController: UICollectionViewController, UICollectionViewDelegateFlowLayout {

func getContext () -> NSManagedObjectContext {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
return appDelegate.persistentContainer.viewContext
}





var dayPlan: [DayPlan] = {

var mondayDayPlan = DayPlan()
var mondayDayPlanWorkout : Workout?
mondayDayPlan.dayNameLabel = mondayDayPlanWorkout?.mondayNameCD
mondayDayPlan.codeNameLabel = mondayDayPlanWorkout?.mondayCodeNameCD
mondayDayPlan.task01 = mondayDayPlanWorkout?.mondayTask01
mondayDayPlan.task02 = mondayDayPlanWorkout?.mondayTask02
mondayDayPlan.task03 = mondayDayPlanWorkout?.mondayTask03
mondayDayPlan.task04 = mondayDayPlanWorkout?.mondayTask04
mondayDayPlan.task05 = mondayDayPlanWorkout?.mondayTask05
mondayDayPlan.dayIconImage = #imageLiteral(resourceName: "biceps")



var tuesdayDayPlan = DayPlan()
tuesdayDayPlan.dayNameLabel = "Tuesday"
tuesdayDayPlan.codeNameLabel = "pojdme na ty nohy"
tuesdayDayPlan.task01 = "5x1 Legs"
tuesdayDayPlan.task02 = "5x2 Legs"
tuesdayDayPlan.task03 = "5x3 Legs"
tuesdayDayPlan.task04 = "5x4 Legs"
tuesdayDayPlan.task05 = "5x5 Legs"
tuesdayDayPlan.dayIconImage = #imageLiteral(resourceName: "ass")
return [mondayDayPlan, tuesdayDayPlan]

我有这个核心数据模型:

Entity: **Workout**
with this Attributes:
mondayCodeNameCD
mondayFocusCD
mondayNameCD
mondayTask01
mondayTask02
mondayTask03
mondayTask04
mondayTask05
mondayTask06
more, more, more...

tuesdayDayPlan 是硬编码的(工作良好),但 mondayDayPlan 与 CoreData 一起使用(显示 nothink)...没有错误,但星期一是空的,为什么?这种情况下如何从CoreData获取数据呢?谢谢...

最佳答案

听起来好像您没有将数据正确保存到核心数据中。您可以通过打开以下内容轻松检查:〜/库/应用程序支持/iPhone模拟器/用户/应用程序/

按“修改日期”排序以查找您刚刚构建的应用。找到 .sqlite 文件。检查应该存在的数据是否确实存在。

每次将 NSManagedObject 添加到核心数据后,请确保写入“appDelegate.saveContext()”。

祝你好运!

关于ios - Swift CoreData 到 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42147885/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com