0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AppIntentsのParameterで写真を読み込みたい

Posted at

結論: IntentFileを使う

Parameterで写真を読み込みたかったのだが、Imageなどの型は対応していないのでIntentFileという型を使う必要がある。データの型なので、そのままでは画像としては使えない。UIImageに変換したりする必要がある。

//ParameterはIntentFile型
@Parameter(title: "Photo", supportedTypeIdentifiers: ["public.image"], requestValueDialog: IntentDialog("Choose a photo")) var photo: IntentFile

//データをImage型として読み込む
var image: Image?
let data = photo.data
if let uiImage = UIImage(data: data) {
    image = Image(uiImage: uiImage)
}

個人的にはこのような形で使った。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?