Closed PGLongo closed 9 years ago
I can't remember exactly why I added that in the first place, I think it had something to do with either Objective-C users consuming this Swift Framework or modules in Xcode not working as intended. Can you remember?
In previous version it was something like _StringIDon'tRememberClassName.
In current version is SuperRecord.Pokemon so we can add a function or a variable to compute the class name taking the second part of the string. Developer using and older version of Swift (poor poor guys) should use @objc(className) and new developer can avoid it.
I will try it today and make a PR.
I don't know the reason but it seems not working. I have removed @objc(Pokemon) and get the correct name but I received this error:
Unable to load class named 'Pokemon' for entity 'Pokemon'
The instruction @objc(Pokemon) is necessary for some other reason other than
NSStringFromClass(self)
Yea, I literally can't remember why, but there was some important reason :) i'll try remember at some point.
out of interest, did you assign the result of NSStringFromClass(self) to a String or NSString ?
var entityName : NSString = NSStringFromClass(self)
The problem is not the result but the retrieval of the NSManagedObject made by CoreData.
yes, i've seen this before when using Objective-C CoreData in a Swift project and it was caused by functions returning NSString being casted to String.
I resolved it by doing
var entityName : NSString = NSStringFromClass(self) as NSString
but perhaps my magic-tricks don't work here :) i don't have time to dig into it properly now :(
Same error forcing cast as NSString
Entity names in xcdatamodel must be named like ModuleName.ClassName
if @objc(ClassName)
isnt' used. So for the test target, I think you should rename Pokemon
to SuperRecordTests.Pokemon
in model editor.
indeed. However that wasn't working before. ikesyo, please make a PR and test :)
My idea was to avoid forcing the developer to add @objc(ClassName) or doing other strange things. For this reason I think that naming the Entity ModuleName.ClassName is not a solution!!
agreed, its swapping 1 task for another. lets park this for now and see what changes in the final release of swift 1.2
I'd like to somehow demonstrate the entity naming case above. But I'm not with Mac now, it'll be tomorrow or the day after tomorrow :wink:
Entity names in xcdatamodel must be named like ModuleName.ClassName if @objc(ClassName) isnt' used.
Sorry, this wasn't correct. It's not the entity name, but the class name in model editor.
Don't worry. Thanks anyway
In the current version of Swift NSStringFromClass(ClassName) returns // ProjectName.Pokemon.
So we can easily add a new function in NSManagedObject that returns only the ClassName without forcing the user to add @objc(ClassName) to each NSManagedObject.
What do you think @michaelarmstrong?