我正在试着在我的iPhone 4s上运行Swift应用程序。它在模拟器上运行良好,我的朋友也可以在他的iPhone 4s上成功运行。我有iOS 8和官方发布的Xcode 6。

我试过了

重启Xcode, iPhone,电脑 清洁和重建 撤销并创建新的证书/供应配置文件 运行路径搜索路径是$(inherited) @executable_path/Frameworks 包含Swift代码的嵌入内容是“是” 代码签名身份是开发人员

下面是完整的错误

dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/AppName.app/AppName
  Reason: no suitable image found.  Did find:
    /private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/AppName.app/Frameworks/libswiftCore.dylib: mmap() error 1 at
address=0x008A1000, size=0x001A4000 segment=__TEXT in Segment::map() mapping
/private/var/mobile/Containers/Bundle/Application/LONGSERIALNUMBER/APPLICATION_NAME/Frameworks/libswiftCore.dylib

当前回答

我认为直接从Xcode生成证书是一个错误。要解析(至少在Xcode 6.1 / 6A1052d中):

go to the Apple Developer website where certificates are managed: https://developer.apple.com/account/ios/certificate/certificateList.action select your certificate(s) (which should show "Managed by Xcode" under "Status") and "Revoke" it follow instructions here to manually generate a new certificate: https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html#//apple_ref/doc/uid/TP40012582-CH31-SW32 go to Xcode > Preferences > Accounts > [your Apple ID] > double-click your team name > hit refresh button to update certificates and provisioning profiles

其他回答

在Xcode 8中,“嵌入式内容包含Swift代码”选项不再可用。

它已被重命名为“Always Embed Swift Standard Libraries = YES”

我们有一个unity项目,它创建了一个xcode项目,其中包括使用swift的库。

我们尝试了这个话题上的每一个合理的建议。

毫无效果。代码在新设备上运行良好,在iOS上崩溃<=12

看起来swift是如此的聪明,即使你将它设置为"ALWAYS_EMBED_SWIFT_LIBRAIES"="YES",它也不包括swift库。

真正为我们解决问题的是在项目中包含一个虚拟的swift文件。 该文件必须包含对分派、基础库的调用。

显然,这暗示了mighty-xcode强制包含库,但这次是真的。

下面是我们添加的虚拟文件,使其工作:

import Dispatch
import Foundation


class ForceSwiftInclusion {

   init() {

    // Force dispatch library.
    DispatchQueue.main.async {
      print("something")
    }

    // Force foundation library.
    let uuid = UUID().uuidString
    print("\(uuid)")

   }
}

对于统一,也添加项目。AddBuildProperty(target, "SWIFT_VERSION", "Swift 5");到创建xcode项目的后期处理。

Xcode 7.2,一台设备上是iOS 9.2,另一台设备上是9.0。两人都犯了错误。不知道是什么改变导致了它,但上面的WWDR解决方案对我来说是正确的。安装证书,问题就解决了。

https://forums.developer.apple.com/message/43547 https://forums.developer.apple.com/message/84846

我在运行Swift测试时遇到了这个问题(但不是我的应用程序)。事实证明,测试需要在测试目标的Runpath Search Paths构建设置中有更多的@executable_path/Frameworks。以下设置Runpath搜索路径对我来说很有魅力:

$(inherited)
@executable_path/Frameworks
@loader_path/Frameworks

我同时安装了多个版本的Xcode。这个框架是用更新版本的Xcode构建的。我尝试编译的应用程序使用的是较旧版本的Xcode。当我用相同版本的Xcode清理和编译框架和应用程序时,事情就正常了。