Closed hitendradeveloper closed 5 years ago
Is RealmSwiftObject
a custom class of yours?
No its not custom class, its class of Realm framwork
No its not custom class, its class of Realm framwork
RealmSwiftObject
is now the fully qualified Objective-C name of RealmSwift.Object
as of #2979, so you shouldn't name your models by that name. I'll update the docs to reflect this.
Actually, since the compiler should prevent you from declaring classes named RealmSwiftObject
, there's not much more that documentation about it would do to help.
@hitendradeveloper could you please your entire Podfile here? This error could happen if you're using mismatched versions of the 'Realm' and 'RealmSwift' pods.
I have used pods as below in iOS app target.
use_frameworks! pod 'RealmSwift'
also added same pod to watchOS2 extension and my ModelKit framework.
@hitendradeveloper have you made any progress on this since you last posted here? If not, I could spend some time trying to reproduce this next week.
@jpsim No, there is not any progress, still getting the same error.
@jpsim I'm not sure if this is the same issue but I'm getting the same error message...
I have a predominantly Swift project so am using RealmSwift. However, I need to do a little Objective-C (that doesn't use Realm). However, when i #import "ProductModuleName-Swift.h" as Apple's Docs suggest for a mix-and-match project... the "cannot find the interface interface declaration for RealmSwiftObject" error prevents me from compiling.
Has your team encountered this at all? Thanks in advance for any help/advice you have!
I have yet to prepare a sample project that reproduces the issue, so no we haven't encountered this ourselves. If you could share one, that could save some time!
@jpsim absolutely! here you go: https://github.com/danielhour/RealmSwiftSample
thanks again for taking a look at this!
Thanks for the project, @danielhour! I could easily trigger the compilation failure.
To be clear, using Realm Swift from Objective-C is unsupported. This is stated in the first line of our Realm Swift docs:
If you’re looking to use Realm from Objective-C, or from mixed Objective-C & Swift apps please see Realm Objective-C instead.
Realm Objective-C is designed to be used from Objective-C and/or Swift and we support its usage in mixed projects. So I encourage you to use Realm Objective-C if you need to use Realm from Objective-C.
@danielhour in your case, you're not actually trying to use Realm Swift from Objective-C, but rather you need to access some other declarations from the Swift part of your app in the Objective-C part of your app. So you're "playing within the rules" so to speak. In that case, you can hide your Realm model classes from your -Swift.h
header by marking them private
:
private class RObject: Object
By doing that your project compiles for me.
@jpsim so i actually tried that and while that removes that error.. then my other swift files can no longer see that class. is there another way to hide it? thanks.
Manually editing the -Swift.h
file to avoid redeclaring your Realm models? You'd have to stop Xcode from auto-generating the file and pass in your own.
@jpsim I am using mix and match environment,
I was just trying to create modelKit, so I can share the pure swift classes between watch and iOS app, all the classes are subClass of Object, Object class is part of Realm.
I have not used and Objective-C code, compiler automatic generates the -Swift.h header file, that's why I am getting the error.
About your solution to make private, in this case how we can share classes with other target, they will not visible anymore by making them private.
Thanks for sharing, I'll reopen this and take another look for potential workarounds later.
@jpsim Is there any progress about the issue ?
I'm working on a fix in Swift's PrintAsObjC.cpp.
I've just filed SR-805 to track this on Swift's bug tracker.
Until this is fixed, I'd encourage you to work around this by only including the -Swift.h
file from an Objective-C file, re-exposing the methods you want to use, and importing that from your Objective-C++ file.
Hacky workaround:
There is no way to exclude classes from the *-Swift.h without making them private, but what you can do is open the Swift.h file, remove all classes with errors (or just keep the class/es you need to access), copy what's left into a new file (e.g. SwiftBridge.h) in your project, and import that one instead.
This will of course need to be redone to add new classes / methods. For me that's not really an issue though, as I only need to call one Swift-class from ObjC, that doesn't change often.
The class reference looks like this:
SWIFT_CLASS("_TtC10tripfinger21TripfingerAppDelegate")
That's the module name and the class name, prefixed by the length of their names. So if they change names, you also have to go through the process again.
I'm in the same boat, with a Swift and Obj-C++ mix.
Since none of the Realm-related classes are ever used on the ObjC-side, I can work around this problem by having #define RealmSwiftObject NSObject
just before the #import "xyz-Swift.h"
Looking forward for the progress on this issue. Any updates ?
No updates on our side. SR-805 is still up for grabs. @hitendradeveloper is this something you're interested in fixing in the Swift compiler?
@gereons Thanks for the workarounds, we are currently encounter the same issue on our end and lucky saw this workaround.
And btw, #define RealmObjectSwift NSObject
should be -> #define RealmSwiftObject NSObject
@vincent-peng Thanks, I've edited my comment to reduce further confusion.
Any good news with swift 4.0?
I checked @jpsim 's sample code PrintAsObjcBug
with Xcode 9 beta 1. But getting same error. This will remain impossible in future too?
I'm in the same boat, with a Swift and Obj-C++ mix.
Since none of the Realm-related classes are ever used on the ObjC-side, I can work around this problem by having
#define RealmSwiftObject NSObject
just before the#import "xyz-Swift.h"
This is still working for me to fix the same error on Xcode10.2 with Swift5, realm-cocoa v3.14.0
Cannot find interface declaration for 'RealmSwiftObject', superclass of MyObject
. Mix Swift 5 and Obj-C.
dito, Swift-only (except obj-c in imported frameworks).
❗️Swift Compiler Error: Cannot find interface declaration for 'RealmSwiftObject', superclass of 'MyRealmObject'. Pure Swift 5.
In my case it was related to Carthage bug.
@3a4oT, how did you resolve the Carthage bug? Thanks.
depends on https://github.com/Carthage/Carthage/pull/2748 and https://github.com/Carthage/Carthage/pull/2723. Carthage should release later this week. For now I have postponed Xcode 10.2 migration.
depends on Carthage/Carthage#2748 and Carthage/Carthage#2723. Carthage should release later this week. For now I have postponed Xcode 10.2 migration.
The build should work for Generic iOS Device, but fails for builds to simulators.
I have the same problem: Xcode 10.2 Swift 5.0 Carthage 0.33.0 I writing only in Swift, don't have Objective-C in my project
Update Carthage does't resolve this issues
I have updated to last realm-cocoa version (3.14.1) where it is supposed to be fixed, but still failing. Have anyone find a solution?
For me it was an issue with Carthage. Updating to Carthage 0.33.0 resolved all the issues.
This seems to be working for me now - with Realm 3.14.1 and the pre-built binary. Carthage 0.33 but since it's pre-built maybe that doesn't matter? I also deleted the cached version in ~/Library/Caches/org.carthage.kit and I deleted the binaries from my Carthage/Build folder too
This seems to be working for me now - with Realm 3.14.1 and the pre-built binary. Carthage 0.33 but since it's pre-built maybe that doesn't matter? I also deleted the cached version in ~/Library/Caches/org.carthage.kit and I deleted the binaries from my Carthage/Build folder too
Clear all the caches you mentioned did the trick.
I still see this issue Obj-C + Swift 5
I have just started working on watch app, I want to share my Realm model classes to watch app also,
To make data available for watch app using NSKeyedArchiver and NSKeyedUnarchiver using WatchConnectivity, I have make CocoaTouch Framework which includes model classes, and added "pod 'RealmSwift'" to framework target.
When I compile the Project, it is giving error ''
I have changed SWIFT_INSTALL_OBJC_HEADE to NO