Mac Swift-如何下载图像并将其加载到NSImageView?

Mac Swift-如何下载图像并将其加载到NSImageView?,swift,image,macos,nsimageview,Swift,Image,Macos,Nsimageview,我想从URL下载一个图像,并在我的swift OSX应用程序中显示它。iOS的解决方案不适用于OSX 我想下载图像并在NSImageView中显示它。只需: let image = NSImage(byReferencingURL:NSURL(string: "http://theinterweb.net/ico/robotics_notes.gif")!) let imageView = NSImageView() imageView.image = image 您可以在Objective-

我想从URL下载一个图像,并在我的swift OSX应用程序中显示它。iOS的解决方案不适用于OSX

我想下载图像并在NSImageView中显示它。

只需:

let image = NSImage(byReferencingURL:NSURL(string: "http://theinterweb.net/ico/robotics_notes.gif")!)
let imageView = NSImageView()
imageView.image = image
您可以在Objective-C中获取或:

NSImage *image = [[NSImage alloc] initByReferencingURL:[NSURL URLWithString:@"http://theinterweb.net/ico/robotics_notes.gif"]];
NSImageView *imageView = [[NSImageView alloc] init];
imageView.image = image;

当然,您可以将URL加载到NSData中,然后根据需要转换为NSImage,就像在iOS上一样。

您所说的“不适用于OSX”是什么意思?@qop查看图像时不会添加任何信息。让我们避免显示动画GIF,如果它们与当前问题无关。谢谢!:)