简体   繁体   中英

How can i Create or Generate New Entity on RunTIme In Swift

I am working on a core Data based project. I want to create dynamic core data entities on runtime with name of current date. Thanks

You cannot create entities dynamically but you can create managed objects dynamically, in your object graph.

Probably you should read a little of the Core Data Programming Guide . At least read up to and including the section Creating and Saving Managed Objects , which explains the answer to your first question in great detail.

Regarding the name of the current date , if you mean a string expressing the current date, you should first add such an attribute to your entity. It is more conventional and usually better for localization to make this attribute of type date and transform to/from a string for the user interface. You get the current date with Date.init() object, and convert it to a string using a DateFormatter .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM