Giter VIP home page Giter VIP logo

Comments (6)

hdost avatar hdost commented on August 16, 2024 1

This will fix your woes

@objc(MyManagedClass)
class MyManagedClass: NSManagedObject {

}

NSStringFromClass(MyManagedClass)

image

from objectiverecord.

bartjacobs avatar bartjacobs commented on August 16, 2024

This could be solved by inspecting the result of NSStringFromClass, breaking the string up in components separated by ., and returning the last component.

+ (NSString *)entityName {
    NSString *entityName = NSStringFromClass(self);

    if ([entityName containsString:@"."]) {
        NSArray *components = [entityName componentsSeparatedByString:@"."];
        if (components.count > 1) entityName = components.lastObject;
    }

    return entityName;
}

from objectiverecord.

Tylerc230 avatar Tylerc230 commented on August 16, 2024

My work around was to override entityName in a subclass.

On Thursday, February 19, 2015, Bart Jacobs [email protected]
wrote:

This could be solved by inspecting the result of NSStringFromClass,
breaking the string up in components separated by ., and returning the
last component.

  • (NSString *)entityName {
    NSString *entityName = NSStringFromClass(self);

    if ([entityName containsString:@"."]) {
    NSArray *components = [entityName componentsSeparatedByString:@"."];
    if (components.count > 1) entityName = components.lastObject;
    }

    return entityName;
    }


Reply to this email directly or view it on GitHub
#115 (comment)
.

from objectiverecord.

DenTelezhkin avatar DenTelezhkin commented on August 16, 2024

I've been struggling with class names in my frameworks as well, here's the solution i came up with:

https://github.com/DenHeadless/DTModelStorage/blob/master/DTModelStorage/Utilities/DTRuntimeHelper.m#L13-L22

This is basically NSStringFromClass, but language-independent, which returns class name in objective-c, and second part of class name in Swift(first is module name).

from objectiverecord.

tomaszwojcik avatar tomaszwojcik commented on August 16, 2024

I use Swift 1.2 and XCode 6.3 and I'm still getting the Cannot create an NSPersistentStoreCoordinator with a nil model error.

Any ideas where I failed? Here's what fails and my steps:

var sample = Sample.create() as! Sample

  1. Removed obsolete CoreData code from AppDelegate (earlier I have added it manually).
  2. Created new xcdatamodeld named like my project, let's say: MyProject.xcdatamodeld.
  3. Added new entity Sample with few fields and generated a class or it. In entity the configuration I tried both MyProject.Sample and Sample as a class.
  4. Tried with with overriding entityName and @objc annotation.

I managed to get such error:
CoreData: error: Failed to call designated initializer on NSManagedObject class 'Sample'

from objectiverecord.

reaperdtme avatar reaperdtme commented on August 16, 2024

Just popped a swift version.
Cheers!
https://github.com/arkverse/SwiftRecord

from objectiverecord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.