Swift: Using Protocol inside another Target can´t find some properties

Viewed 280

I currently have a big problem inside my ios application.

Our Project structure looks like this:

  • 1 SDK (3rd Party Library), written in Objective-C
  • 1 "Common" framework, which contains the shared code (overall most code lives here & everything related to the SDK from above)
  • different targets for different clients, which are just defining custom colors and custom images for our "Common" framework.

Inside the Common framework we added a new Protocol to wrap all of the SDK features, it looks somehow like that:

protocol SDKRepositoryProtocol {

var oneClassFromSDK : SDKClass123 { get set }
[...]
var otherTestProp: SDKCustomDate { get set } 

}

So SDKClass123 and SDKCustomDate are private classes from the SDK.

Using the SDKRepository class works fine inside our "Common" Framework and most of our targets are built successfully with no errors at all.

Now, here is the problem:

If we now want to use the SDKRepositoryProtocol inside one of our targets, the IDE is supporting our usage and IntelliSense shows all of the protocols variables, but if we want to compile our Swift file we get an error like:

Value of type 'SDKRepositoryProtocol' has no member 'oneClassFromSDK'.

Note:

  • this only happens on the 'Release' Build Configuration & not in DEBUG

And what even is more mysterious, if we try to access repoProtocol.otherTestProp its working in both Build Configurations.


So, next we tried to use the same Protocol inside our TargetAppDelegate for the same target (which is still written in Obj-C). And there is no issue using the property repoProtocol.oneClassFromSDK

So is there any other problem if we just create a new extension for TargetAppDelegate (for using Swift) ? Do we need to define sth. more ?


So, for me it seems like:

a) the compiler for release builds is causing problems and removes properties, which he thinks are not used ('oneClassFromSDK')

b) the overall SDK is not imported into the target, because oneClassFromSDK cant be used inside Swift, but otherTestProp compiles without problems

c) hope you have some good ideas


summary:

  • we have a protocol inside the common framework
  • inside AppDelegate (ObjC) of the target we have access to all properties (Debug & Release Builds)
  • inside the Swift Extension from AppDelegate we have no access to some properties (not all), and only in the Release Build

Things we tried:

  • some general stuff: Clean Build / Clean Derived Folder / Not working on another PC
  • we already tried to find differences inside the debug / release configuration
    • we did not find any
    • we also tried to just "brute-force" the configuration from another target (where we can use the protocol)
  • we checked if the file is included twice, so there are two mismatching protocols, but inside our project file its only once
    • we also tried to toggle the target membership, because this helped in the past to reset issues inside the project configuration file

Edit:

So, we could minify our problem to basically one file:

class MyCustomServiceInTarget: NSObject {
    let shello: SDKClass123
    let repo: SDKRepositoryProtocol

    init(repoProtocol: SDKRepositoryProtocol) {
        self.repo = repoProtocol

        var x = repoProtocol.oneClassFromSDK // Will produce an error 
    }

So, inside this Service we get the error like above. The Service was used inside the Targets AppDelegate, so it initially showed up there, too.

Now, imagine: If we comment out the line let shello: SDKClass123 and try to use the repo.shell property again, it is working !!! :O :O

Can anybody explain this ??

0 Answers
Related