0

So i'm having trouble with trying to open xcode with core data checked.

everytime i do it my old file from years ago suddenly shows up with all the old codes attached and my core data already filled in with that previous attemp. i have tried everything from deleting xcode to deleting my files but i cannot understand where and how xcode saves that old codes and keeps popping it up again and again everytime i clicked that core data check mark. i don't know if its a cache thing because i saw you can delete xcode cache but you have to download some software and i believe apple probably has some built in thing to avoid this. i'm using xcode 13.2.1 please help i've been trying and wrapping my heads around this problem for sometime i can;t seem to find the right answer for it. i have tried to delete xcode profiles like in this article https://cocoacasts.com/how-to-delete-every-record-of-a-core-data-entity

even this https://www.advancedswift.com/batch-delete-everything-core-data-swift/#delete-everything-delete-all-objects-reset-core-data

i still don't understand how to delete them all or where the code should be placed

Thank you so much for your time and have an amazing day/evening

arman
  • 191
  • 1
  • 5
  • 1
    Welcome to SO - Please take the [tour](https://stackoverflow.com/tour) and read [How to Ask](https://stackoverflow.com/help/how-to-ask) to improve, edit and format your questions. Without a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) it is impossible to help you troubleshoot. Your question is poorly worded and doesn’t make a whole lot of sense, if we put bits an pieces together we could come up with a handful of very different solutions. – lorem ipsum Feb 16 '22 at 15:30
  • I'm sorry about that but i tried to convey it as simply as possible as if everyone is a busy colleague however its hard to describe the experience without going into detail let me give it another try: When i turn on my xcode and clicking through to make an app with core data my old codes from years ago pops up and i can't seem to get rid of it do you know how to get xcode to open up a fresh new app view without my old codes already appearing before hand? – arman Feb 16 '22 at 15:36
  • 1
    Your code appears or the old objects you created? Code being the stuff contained in swift files and objects being the data you created based on the core data entities. – lorem ipsum Feb 16 '22 at 16:05
  • What I think your issue may be is that your old stores with objects keep appearing, not code. You likely need to “destroy” the store on the devices/simulators, you’ll find the code you need [here](https://stackoverflow.com/questions/70482430/mock-core-data-object-in-swiftui-preview/70482536#70482536) the other possibility is that you used/are using CloudKit. So you need to clear CloudKit Settings>iCloud>Manage Storage>Your App>Delete Data. Both things combined on all the devices will delete everything in CoreData/App folder so be cautions. – lorem ipsum Feb 16 '22 at 16:13
  • When i tried to delete the iCloud data doesn't have a "Your App" it just had documents and i tried to delete the documents but it deleted both from iCloud and stored files Furthermore i still have no idea how to "Destroy" the store on the devices simulators because my persistence file has no "container = NSPersistentCloudKitContainer(name: "YourAppName")" it only has let container: NSPersistentContainer i followed this from a tutorial so i don't really understand its implication – arman Feb 17 '22 at 00:18
  • Refer to my first comment. Nobody knows what “codes” means. – lorem ipsum Feb 17 '22 at 00:36
  • Okay, this thing thing won't go away no matter how many times i delete the files or trying to destroy it it always comes back the same way everytime i clicked the checked button on core data when i'm trying to start a new project: static var preview: PersistenceController = { let result = PersistenceController(inMemory: true) let viewContext = result.container.viewContext for _ in 0..<10 { let newItem = Item(context: viewContext) newItem.timestamp = Date() – arman Feb 17 '22 at 00:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/242091/discussion-between-arman-and-lorem-ipsum). – arman Feb 17 '22 at 00:44
  • Are you talking about the file that contains that line of code? That line of code is a template file. It appears on everybody’s Xcode when they start a new project with core data . You can delete it afterwards but you can’t start a project with core data without it. The Item entity, the content view file and the persistent controller are template. – lorem ipsum Feb 17 '22 at 00:46
  • There is a link i have sent to you of a video about the problem i'm facing. the thing is on the tutorial the guy had clean slate nothing else but i had this time.formatter thing is that common to have this in you contextView @Environment(\.managedObjectContext) private var viewContext @FetchRequest( sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)], animation: .default) private var items: FetchedResults var body: some View { NavigationView { List { ForEach(items) – arman Feb 17 '22 at 00:56
  • 1
    I don’t have Facebook, but that code is template, everybody gets it when they select core data. The only way to get a clean slate is not select core data and then you create the stack, model, etc yourself. If the tutorial is old the stack would be in the App delegate. – lorem ipsum Feb 17 '22 at 01:02
  • So, its okay then and i can just delete everything should i delete the persistence.swift file as well or not? – arman Feb 17 '22 at 01:54
  • You can delete it but do you need coredata? Do you know how to Create the stack from scratch? Without that code there is no access to core data. – lorem ipsum Feb 17 '22 at 02:07
  • what does the persistence file actually do if i might ask and to answer your previous questions no i do not – arman Feb 18 '22 at 00:29
  • The persistence file has a `preview` and `shared` Core Data Stack. You can't access CoreData without it or without something similar to it https://developer.apple.com/documentation/coredata/setting_up_a_core_data_stack there are plenty of tutorials out there that will teach you all about it – lorem ipsum Feb 18 '22 at 00:37

0 Answers0