简体   繁体   English

扩展名为“架构arm64的未定义符号”

[英]“Undefined symbols for architecture arm64” on extension

My app builds fine, but now I'm attempting to build for Archive, and I'm getting this error: 我的应用程序构建正常,但现在我正在尝试为Archive构建,我收到此错误:

Undefined symbols for architecture arm64:
  "type metadata for (extension in TwIM):__ObjC.NSData.ImageType", referenced from:
      static TwIM.ImageCache.imagePath (imageURL : __ObjC.NSURL, imageType : (extension in TwIM):__ObjC.NSData.ImageType?) -> Swift.String? in ImageCache.o
      function signature specialization <Arg[0] = Owned To Guaranteed and Exploded> of static TwIM.ImageCache.imagePath (identifier : Swift.String, imageType : (extension in TwIM):__ObjC.NSData.ImageType?) -> Swift.String? in ImageCache.o
      function signature specialization <Arg[0] = Owned To Guaranteed and Exploded> of static TwIM.ImageCache.imageData (identifier : Swift.String, imageType : (extension in TwIM):__ObjC.NSData.ImageType?) -> __ObjC.NSData? in ImageCache.o
      function signature specialization <Arg[0] = Owned To Guaranteed and Exploded> of static TwIM.ImageCache.image (identifier : Swift.String, imageType : (extension in TwIM):__ObjC.NSData.ImageType?) -> Swift.AnyObject? in ImageCache.o
      function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Owned To Guaranteed and Exploded> of static TwIM.ImageCache.saveImage (imageData : __ObjC.NSData, identifier : Swift.String, imageType : (extension in TwIM):__ObjC.NSData.ImageType?) -> Swift.Bool in ImageCache.o
      function signature specialization <Arg[0] = Owned To Guaranteed and Exploded> of static TwIM.ImageCache.removeImage (identifier : Swift.String, imageType : (extension in TwIM):__ObjC.NSData.ImageType?) -> () in ImageCache.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What it's referring to is an extension I have on NSData, which includes an enum: 它所指的是我在NSData上的扩展,其中包含一个枚举:

extension NSData {
  enum ImageType: String {
    case jpg = "jpg"
    case png = "png"
    case gif = "gif"
  }
}

I don't know why this would be causing an issue. 我不知道为什么会引起这个问题。 I've cleaned, and cleared derived data as some people have suggested. 我已经清理过,并清除了一些人建议的派生数据。

Which Xcode and which Swift version do you use? 您使用哪个Xcode和哪个Swift版本?

I first discovered this error message with Xcode 8 and Swift 3 beta 6. I had a look on what I imported but it was only Cocoa for all files. 我首先使用Xcode 8和Swift 3 beta 6发现了这个错误消息。我看了一下我导入的内容,但它只是所有文件的Cocoa。 There were several errors of this kind, almost all belonging to a function, which was very large. 有这样的几个错误,几乎都属于一个非常大的函数。 The error only happens, if Global-Module-Optimization is selected, regardless if running or archiving. 如果选择了Global-Module-Optimization,则只会发生错误,无论是运行还是归档。

So I divided this function in 6 smaller parts to look, which one was causing the problem. 所以我把这个功能划分为6个较小的部分来看,哪一个引起了问题。 After making the function smaller, only two errors of this kind stayed. 使功能变小后,只剩下这种错误。 So I think it is a linker/optimizer-Problem in my case, because the code is the same, only divided in several small functions. 所以我认为它是一个链接器/优化器 - 在我的情况下问题,因为代码是相同的,只分为几个小函数。

Please try to select Single-File-Optimization for Release and try to Archive. 请尝试选择Single-File-Optimization for Release并尝试存档。 Does the error come again or are you successfull? 错误会再次出现还是您成功了?

I guess, this will be not a problem in the final release. 我想,这不会是最终版本中的问题。

I had this problem too. 我也有这个问题。 And I solved this with following operations: 1. Go to build setting. 我通过以下操作解决了这个问题:1。转到构建设置。 2. Search for enable testablility. 2.搜索启用testablility。 2. Set No for Debug. 2.为调试设置否。

Try getting rid of the enum. 尝试摆脱枚举。 That's what fixed it for me. 这就是为我解决的问题。 Maybe there's a problem with enums in extensions. 也许扩展中的枚举存在问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM