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

Chris
  • 2,739
  • 4
  • 29
  • 57
  • 2
    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. – milo526 Apr 24 '15 at 15:32
  • Hi Yes, The class is added to the build phases – Chris Apr 24 '15 at 15:34
  • Is that class one of your own classes or from a framework you are using? – Christian Apr 24 '15 at 17:31

10 Answers10

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.

superarts.org
  • 7,009
  • 1
  • 58
  • 44
  • 2
    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 armv7s – user2363025 Feb 02 '17 at 16:10
  • 9
    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. – user2363025 Feb 02 '17 at 16:23
  • have both module but still not working for iPhone 5 and iPhone 4 – Muhammad Shauket Aug 20 '18 at 14:26
  • @ShauketSheikh I think iPhone 5 is `armv7s`, and iPhone 4 is `armv6`. – superarts.org Aug 21 '18 at 01:53
  • @superarts.org in build setting of frameowrk project these are my architecture, arm64, armv7, armv7s – Muhammad Shauket Aug 21 '18 at 03:29
  • 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 error – Muhammad Shauket Aug 21 '18 at 03:30
  • 1
    Thank you so much! In my case, I'm having arm modules so I tried running it on device it works good. – Vinoth Vino Oct 15 '18 at 08:02
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.

Akram
  • 2,158
  • 1
  • 17
  • 24
  • 1
    @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. – Akram Nov 10 '17 at 16:49
  • Setting ‘Build Active Architectures’ to ‘No’ in the Framework’s project may prevent this from happening again. – Josh Paradroid Jul 14 '22 at 15:27
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.

AdamPro13
  • 7,232
  • 2
  • 30
  • 28
6

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

User31
  • 279
  • 3
  • 11
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.

Akram
  • 2,158
  • 1
  • 17
  • 24
yashwanth77
  • 1,820
  • 1
  • 12
  • 17
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.

Yitzchak
  • 3,303
  • 3
  • 30
  • 50
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!

Lokesh SN
  • 1,583
  • 7
  • 23
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?

Andoni
  • 1
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

amleszk
  • 6,192
  • 5
  • 38
  • 43
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

Nick Greg
  • 221
  • 4
  • 7