作者:嗯明天娶你 | 来源:互联网 | 2023-08-26 20:33
Icurrentlyhaveaplistfilethatcontains27achievementsdataandimtryingtoenteritintothe
I currently have a plist file that contains 27 achievements data and i'm trying to enter it into the core data entity know as achievement as seen below
我目前有一个plist文件,其中包含27个成就数据,我正在尝试将其输入核心数据实体,称为成就,如下所示
func createAchievements() {
let A:Achievement = NSEntityDescription.insertNewObject(forEntityName: "Achievement", into: CoreDatabaseContoller.getContext()) as! Achievement
let filePath = Bundle.main.path(forResource: "Achievement", ofType: "plist")
let Items = NSArray(contentsOfFile: filePath!) as! [[String:AnyObject]]
for item in Items {
A.theName = item["Name"] as! String
A.theDescription = item["Description"] as! String
A.theImage = item["Image"] as! String
A.aAmount = item["Amount"] as! NSNumber
A.aNeededAmount = item["NeededAmount"] as! NSNumber //DOESN'T WORK IT ONLY SHOWS OR PUTS IN THE LAST ONE.
A.aStage = item["Stage"] as! NSNumber
A.aReward = item["Reward"] as! NSNumber
A.aHasBeenAchieved = item["HasBeenAchieved"] as! NSNumber
A.theSearchName = item["SearchName"] as! String
CoreDatabaseContoller.saveContext()
}
}
But when I load up the game and the achievements menu part of the game that displays the achievements all the images and text that are supposed to be filled by core data are not there and the images are red Xs except the last achievement in the achievement menu which seems to be working properly as seen inn the picture below
但是当我加载游戏和显示成就的游戏的成就菜单部分时,应该由核心数据填充的所有图像和文本都不存在,并且除了成就菜单中的最后成就之外,图像是红色X这似乎正常工作如下图所示
I originally entered the data from the achievements through a switch system that looked horrible in my code as seen below and it worked not problem. But now for some reason when I try and enter it from a plist to core data it seems to not work
我最初通过一个在我的代码中看起来很糟糕的交换机系统从成就中输入数据,如下所示,它没有问题。但是现在由于某些原因,当我尝试从plist到核心数据输入它时,似乎无法正常工作
func giveDataForAchievements() {
func giveDataForAchievements(){
if achievementsGenerated == false {
for count in 1...24 {
var aName = "None"
var aDesc = "None"
var aImage = "locked"
var aAmount:NSNumber = 0
var aNeededAmount:NSNumber = 1
var aStage:NSNumber = 0
var aReward:NSNumber = 0
var aHasbeenAchieved:NSNumber = 0
var aSearchName = ""
switch count {
case 1:
aName = "DAILY"
aDesc = "Daily Achievement"
aImage = "locked"
aAmount = 0
aNeededAmount = 1
aStage = 0
aReward = 350
aHasbeenAchieved = 0
aSearchName = "Ach0"
case 2:
aName = "DAILY"
aDesc = "Daily Achievement"
aImage = "locked"
aAmount = 0
aNeededAmount = 1
aStage = 0
aReward = 350
aHasbeenAchieved = 0
aSearchName = "Ach1"
case 3:
aName = "DAILY"
aDesc = "Daily Achievement"
aImage = "locked"
aAmount = 0
aNeededAmount = 1
aStage = 0
aReward = 350
aHasbeenAchieved = 0
aSearchName = "Ach2"
case 4:
aName = "ROOKIE"
aDesc = "Finish the tutorial level"
aImage = "locked"
aAmount = 0
aNeededAmount = 1
aStage = 2
aReward = 350
aHasbeenAchieved = 0
aSearchName = "Ach3"
createAchievements(aName: aName, Des: aDesc, Image: aImage, Amount: aAmount, Needed: aNeededAmount, Stage: aStage, Reward: aReward, BeenAchieved: aHasbeenAchieved, SearchName: aSearchName)
// all the way to 27
I am not sure how to fix this. Can anyone tell me what i'm doing wrong?
我不知道如何解决这个问题。谁能告诉我我做错了什么?
1 个解决方案