AsyncImage를 사용하여 이미지를 띄우려고 했는데 다음과 같은 에러가 발생했다.
Value of type 'AsyncImagePhase' has no member 'resizable'
아무리 코드를 들여다보아도 왜 resizable()을 적용할 수 없는 것인지 이해가 되지 않았는데 SwiftUI Documentation - AsyncImage 페이지에서 해답을 얻을 수 있었다.
찾아보니 AsyncImage에는 resizable()과 같은 image-specific modifier를 바로 적용할 수 없다고 한다.
대신 View의 모양을 정의할 때 content closure가 가져오는 Image 인스턴스에 적용을 해야한다고 하는데 코드로 살펴보자면 아래와 같다.
AsyncImage(url: URL(string: "https://www.apple.com")) { image in
image.resizable()
} placeholder: {
ProgressView()
}
placeholder가 없는 경우, Image 인스턴스를 가져와야 할 content closure가 AsyncImagePhase를 받게 된다. 그렇게 되면 resizable()을 적용할 수 없으므로 처음과 같은 에러가 발생한다.
잘 봤습니다. 좋은 글 감사합니다.