Unresolved identifier CGImageSourceCreateWithURL

I have been doing the SwiftUI tutorials, and I am encountering an odd error on the Creating a watchOS App tutorial. Prior to creating the watchOS target, the iOS app builds and runs on the emulator just fine. However, after simply adding the watchOS target, the project fails to build because two of the Core Graphics symbols are now unresolved:


/Users/snipped/../Data.swift:55:27: Use of unresolved identifier 'CGImageSourceCreateWithURL'
/Users/snipped.../Data.swift:56:21: Use of unresolved identifier 'CGImageSourceCreateImageAtIndex'


It doesn't make sense why these two symbols would suddenly be unresolved, though I am not yet very familiar with the arcane magic of the XCode build system. I am intentionally building upon my code from the previous tutorials as a learning exercise.


Does anyone have any pointers for how to debug this issue?


Additional info:


$ xcodebuild -version
Xcode 11.3.1
Build version 11C504
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.1
BuildVersion: 19B77a

CGImageSourceCreateWithURL is available in watchOS.


Could you show the code where you call it ?

How did you define the different targets ?

It looks like, you missed import in Data.swift
Code Block
import ImageIO

That is because you use the previous tutorial project and add a target for watchOS, but the file Data.swift in previous tutorial project not import ImageIO,so you should import this module。
Unresolved identifier CGImageSourceCreateWithURL
 
 
Q