MyClass is unavailable: cannot find Swift declaration for this class - Release Build Only
Asked Answered
D

10

31

I am getting the following error:

MyClass is unavailable: cannot find Swift declaration for this class

but I only get it when doing a release build in Xcode...Debug works fine.

Anyone know what's up? I'm running 6.3

Dieterich answered 24/4, 2015 at 15:29 Comment(3)
Do you add the class to the Build Phases? (Build Phases -> Compile Sources). xCode should do this automagically but if it works in debugging this seems like a good thing to check.Ratoon
Hi Yes, The class is added to the build phasesDieterich
Is that class one of your own classes or from a framework you are using?Assert
T
19

In my case, it was because my framework that I am developing was missing one of the Valid Architectures listed in my app's target. All I had to do was the following:

  1. Go to Project file.
  2. Go to Build Settings for the app target you're trying to build. Note the architectures listed under Valid Architectures.
  3. Go to the framework target that is failing.
  4. Make sure all the architectures match.

In my case, my framework was missing arm64.

Telecommunication answered 13/9, 2016 at 23:13 Comment(0)
C
33

If MyClass is inside a dynamic framework (Cocoa Touch Framework), It is likely that you're using a build with wrong architecture. To check, browse your MyClass.framework in finder, and check Modules/AirServiceKit.swiftmodule. There should be something like x86_64.swiftmodule or arm64.swiftmodule, if you're using simulator there should be x86, or arm if you're building for device.

Covering answered 3/3, 2016 at 4:7 Comment(7)
I have the x86_64.swiftmodule but not the arm64.swiftmodule. How do I add in arm64.swiftmodule? In my framework's build settings under valid architecture I have arm64 armv7 armv7sStraightout
I found my issue. I needed to change the deployment target of the framework from the simulator pre-selected option to “Generic iOS Device” and then rebuild the framework.Straightout
have both module but still not working for iPhone 5 and iPhone 4Touchdown
@ShauketSheikh I think iPhone 5 is armv7s, and iPhone 4 is armv6.Covering
@Covering in build setting of frameowrk project these are my architecture, arm64, armv7, armv7sTouchdown
you can try yourself by creating simple framework and intergrate that framework in your any sample helloworl project, run on simulator iphone 4 or iphone 5 only... see it give errorTouchdown
Thank you so much! In my case, I'm having arm modules so I tried running it on device it works good.Anthodium
P
21

In case anyone else encounter this problem:

I had the exact same error and turned out that I had built my framework for an specific emulator. I changed the device (in upper left corner) to Generic iOS device and did a clean and build, then I used the generated .framework file. Everything worked just fine after using this generated .framework file.

Pugnacious answered 29/4, 2017 at 10:41 Comment(2)
@iArezki Drag it to Embedded Binaries part under General tab of your project. In the wizard window which appears click check Copy item if needed option.Pugnacious
Setting ‘Build Active Architectures’ to ‘No’ in the Framework’s project may prevent this from happening again.Distend
T
19

In my case, it was because my framework that I am developing was missing one of the Valid Architectures listed in my app's target. All I had to do was the following:

  1. Go to Project file.
  2. Go to Build Settings for the app target you're trying to build. Note the architectures listed under Valid Architectures.
  3. Go to the framework target that is failing.
  4. Make sure all the architectures match.

In my case, my framework was missing arm64.

Telecommunication answered 13/9, 2016 at 23:13 Comment(0)
B
6

Check the flag value you have set for Build Active Architectures Only in Build Settings for Debug and Release

Brunell answered 12/10, 2016 at 5:2 Comment(0)
M
4

I had faced the same issue i resolved it by doing the following steps

  1. delete the swift framework i.e. move the swift framework to trash

  2. then clean the current project

  3. build the swift framework again

  4. drag the swift framework and drop in the application main directory

  5. add the framework to the embedded frameworks

  6. )then run the project

it works like a charm.your swift framework classes gets recognised in application.

Mandy answered 10/6, 2015 at 14:23 Comment(0)
A
1

I have a different answer, and I’m sure it’ll help many.

Your app projects link to an early iOS version (like iOS 9.0) and your framework links to a newer (like iOS 11.3)

Just change your framework version to iOS 9.0, Clean, (optionally run pod install if your framework uses pods dependencies), Build, and add the framework file to your app project, add to linked binaries and you’ve done =]

One of the reasons that causes this is that iOS 11 supports 64 bit only (arm64), so the framework gets only that architecture, but your app needs 32 architectures too which are missing.

Allen answered 14/5, 2018 at 19:49 Comment(0)
E
1

I presume you're talking about a framework class

Let's just skip the technical stuff that happens in the background... (Almost everything regarding that has been explained :-) )

This error is just due to the framework's incompatibility for the build that you're trying to run it on..

Fix:-

1) Delete the framework from your project

2) Then:-

  • If you're running a simulator, go to your framework project and build the framework project selecting a simulator from the iOS Simulators list(any device from the simulators list) and then import the framework to the host project

  • If you're running a physical device, go to your framework project and build the framework project selecting "Generic iOS Device"/Physical Device(that's connected) and then import the framework to the host project

It should be working fine now. Hope this helps!

Engagement answered 3/9, 2018 at 7:31 Comment(0)
A
0

Have you tried to look at your scheme on your framework and see if it's pointing to "Release" under Product->Scheme->Run->Build configuration?

Ashburn answered 10/8, 2018 at 11:2 Comment(0)
P
0

None of these answers solved my particular issue. The problem for me was, at some point (can't remember why) I added a custom module map file containing code such as:

framework module Foo {
    umbrella header "Foo.h"
    module * { export * }
    export *
}

This conflicted with the Swift class for some reason. Deleting the modulemap file from the framework target fixed the error

Ptyalism answered 23/6, 2020 at 10:34 Comment(0)
M
0

For custom pod frameworks that use objc + swift:

Create a new header file like: {FrameworkName}.h and add:

#import "{FrameworkName}-umbrella.h"

and then do either a pod install... or add this file inside {FrameworkName}-umbrella.h like this: #import {FrameworkName}.h

Murmuration answered 11/6, 2021 at 13:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.