Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate NSManagedObject classes in Objective C instead of Swift?

I have coreData swift class defined as

import Foundation
import CoreData

@objc(Users)
public class Users: NSManagedObject {

}

Name of file is

Users+CoreDataClass.swift

I need to call this as

NSFetchRequest* request = [Users fetchRequest];

I have tried importing "Users+CoreDataClass-Swift.h" However its not recognising any class with users name.

What am i missing.

like image 310
Muhammad Umar Avatar asked Jan 20 '17 05:01

Muhammad Umar


People also ask

How do I get NSManagedObject?

Still inside the Core Data editor, go to the Editor menu and choose Create NSManagedObject Subclass. Make sure your data model is selected then click Next. Make sure the Commit entity is checked then click Next again.

How do I create a subclass in NSManagedObject?

From the Xcode menu bar, choose Editor > Create NSManagedObject Subclass. Select your data model, then the appropriate entity, and choose where to save the files. Xcode places both a class and a properties file into your project.

What is codegen in Core Data?

The Codegen menu is where you specify the code generation for the entity. There are three code generation options. Choosing Manual/None tells Xcode not to generate code for the entity. You must create the class for the entity by creating a new file or by choosing Editor > Create NSManagedObject Subclass.

How do I use Core Data?

Use Core Data to save your application's permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device. To sync data across multiple devices in a single iCloud account, Core Data automatically mirrors your schema to a CloudKit container.


1 Answers

You can generate Objective-C NSManagedObject subclasses right away. To do so, change your Models settings accordingly:

like image 181
shallowThought Avatar answered Nov 04 '22 03:11

shallowThought