问题
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:
- Go to your project's target
- Choose "General" tab
- Under "Linked Frameworks an Libraries" look for Foundation.framework, select it and press the minus ('-') sign at the buttom to remove this framework.
- 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