I have just updated from Xcode 11 to 12 and tried to compile an existing project which uses Objective-C and Swift 5.
This fails with a lot of errors which say that UIImage does not have a setImage method: Value of type 'UIImageView' has no member 'setImage'
This is strange because in Xcode 11 this complies without any problem. When creating a fresh new project in Xcode 12 I get the same error, but changing the code to someImageView.image = ... works just fine.
However, someImageView.image = ... in my existing project fails with Cannot assign to value: 'image' is a method.
Why does the same code, which compiles in the new project fails in my existing project?
What is the correct way to assign a new image to an UIImageView in swift?
// Fails in Xcode 12 in existing and new project
// Compiles in Xcode 11 in existing project
someImageView.setImage(someImage)
// ==> `Value of type 'UIImageView' has no member 'setImage'
// Fails in Xcode 12 in existing project
// Compiles in Xcode 12 in new project
someImageView.image = someImage
// ==> Cannot assign to value: 'image' is a method
EDIT:
Following the idea of @PhillipMills I now found a UIView extension which implements an image() method:
@interface UIView( Image )
-(UIImage *) image;
-(void) savePNG:(NSString *)filePath;
-(void) saveJPEG:(NSString *)filePath :(float)quality;
@end
This is part of an extension which handles PDF Images within UIImageView. On the other hand the Swift version of UIImageView implement image like this:
open class UIImageView : UIView {
...
open var image: UIImage? // default is nil
}
Both in Xcode 11 and 12 someImageView.image = ... fails and the command click on image cannot be resolved and just shows a ?.
While Xcode 11 resolves someImageView.image() to UIImageView, the same is resolved to the UIView extension in Xcode 12. Why is this?
In Xcode 11 someImageView.setImage(...) is resolved to UIImageView while the same fails in Xcode 12.
Using the setImage() method in Objectiv-C is no problem both in Xcode 11 and 12.
Questions:
- Why is
someImageView.setImage(...)not available in Xcode 12? - Why is
someImageView.image()resolved differently in Xcode 11 and 12?