i'm quite new to objective C and followed some instructions i found, but at the moment i got stuck.
i am trying to load an image with the following code:
NSBitmapImageRep *img;
img = [NSBitmapImageRep imageRepWithContentsOfFile:filename];
"filename" is a valid pointer. But the compiler tells me:
Incompatible pointer types assigning to 'NSBitmapImageRep *' from 'NSImageRep * _Nullable'
What am i missing or doing wrong ?
imageRepWithContentsOfFile:
is a factory method. According documentation, it returns "An initialized instance of an NSImageRep subclass, or nil if the image data could not be read." FromNSImageRep.h
: "If sent to a subclass, does this just for the types understood by that subclass.". So, you need only cast result to specified type:Note that usually you doesn't need to create
NSBitmapImageRep
instances yourself, and can useNSImage
.