Initializes and returns an image object with the contents of the specified file.
SDK
- macOS 10.0+
Framework
- App
Kit
Declaration
convenience init?(contentsOfFile fileName: String)
Parameters
filename
A full or relative path name specifying the file with the desired image data. Relative paths must be relative to the current working directory.
Return Value
An initialized NSImage
object or nil
if the method cannot create an image representation from the contents of the specified file.
Discussion
Unlike init(by
, which initializes an NSImage
object lazily, this method immediately opens the specified file and creates one or more image representations from its data.
The filename
parameter should include the file extension that identifies the type of the image data. This method looks for an NSImage
subclass that handles that data type from among those registered with NSImage
.