Application crashes with - dyld: Symbol not found: _OBJC_CLASS_$_UITraitCollection

走远了吗. 提交于 2019-12-08 12:10:55

问题


dyld: Symbol not found: _OBJC_CLASS_$_UITraitCollection

The only place in the code I have reference to the UITraitCollection is:

func loadImages(imageName: NSString) {
    var image: UIImage
    images = NSMutableArray(capacity: 7)
    for i in 0..7 {
        image = UIImage(named:"\(imageName)\(i).png", inBundle:nil, compatibleWithTraitCollection:nil)

        if (image != nil) {
            images.addObject(image)
        }
    }
}

回答1:


UITraitCollection is only part of the Foundation framework starting with ios8. What this error is saying is that the OS for your phone (7.1.1) doesn't have UITraitCollection in its library, which is true, since this class is only part of the ios8 Foundation.framework library. In order to cut down on app size, the Apple libraries are all dynamically loaded at runtime so they don't have to be packaged with your app, so your app only has access to the ios7 Foundation.framework on that particular iPhone. If you upgrade your iPhone to ios8, it should work.




回答2:


rvijay007's explanation is correct, but the solution is partial (you don't have to upgrade your device to iOS 8! It supports backwards compatibility). Here's the correct answer:

Try re-adding Foundation.framework:

  1. Go to your project's target
  2. Choose "General" tab
  3. Under "Linked Frameworks an Libraries" look for Foundation.framework, select it and press the minus ('-') sign at the buttom to remove this framework.
  4. Now press the plus sign ('+') and search for Foundation.framework - re-add it, and it's supposed to fix your crash.

Hope it works - it did for me.



来源:https://stackoverflow.com/questions/24175678/application-crashes-with-dyld-symbol-not-found-objc-class-uitraitcollecti

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!