PhotoKit을 알아보자 - 1

Hose KIM·2021년 1월 17일
0

iOS 개발

목록 보기
3/4

What is PhotoKit?

PhotoKit 은 프레임워크로 Photo App에서 관리하는 Asset( photo, Video )에 대해서 접근을 가능하게 해준다. → PhoKit을 이용하면 Photo App에 있는 앨범들에게 접근하여 Asset들을 가져올 수 있다.

PHObject

PhotoKit의 객체는 PHObject 객체를 기본적으로 상속받는다. PHObject is the abstract superclass for Photos model objects ( Asset and Collections).

이 객체를 다룰 때, 직접적으로 생성(create)하거나 사용해서는 안된다. (do not use instance of class)

대신에, subclass( PHAssectCollection, PHCollectionList, and PHObjectPlaceHolder)를 이용해서 개발을 해야한다.

PHAsset

포토 라이브러리에 있는 이미지, 비디오, 라이브 포토의 "A representation " 이다. 사진, 비디어, 라이브 포토 하나하나가 PHAsset 인 셈이다.

Asset은 class method인 fectchAssets()을 통해 개발을 시작할 수 있다.

Asset은 메타데이터만을 가지고 있다.

Asset은 immutable이다. (불변성을 가진다.)

PHCollection

Photos asset collections 과 collection lists의 superclass.

이것 역시 PHObject처럼 직접적으로 create 하거나 인스턴스로 작업을 할 수 없다. 대신에 이것의subclass인 PHCollection 또는 PHCollectionList로 작업을 할 수 있다.

PHAssetCollection

PHCollection을 상속받는다. PHAssetCollection은 쉽게 말하면, 앨범이다. (Photos asset grouping)

Photo 프레임워크 안에 있는 collection object들은 member object를 직접 참조할 수 없고, 어떠한 object들도 collection object들을 직접 참조할 수 없다. asset collection의 member를 가지고 오려면, PHAsset class method를 이용해서 fetch 해야한다. 이것 또한 assets 과 collection list와 마찬가지로 immutable하기 때문에 create, rename ... 기타 등등 작업을 하기 위해서 PHAssetCollectionChangeRequest object를 사용해서 photo library를 업데이트 해야 한다.

PHCollectionList

여러개의 Photo asset Collection을 리스트화 한 것이다. ( like Moments, Years folder etc)

위의 PHAssetCollection처럼 멤버들을 직접 참조 할 수 없고 직접 참조될 수 없다. member를 가지고 오려면 PHCollection class method를 이용해서 fetch 해야 한다. 또한 역시 immutable하기 때문에, PHCollectionListChangeRequest를 이용해서 업데이트 해야한다.

PHFetchResult

이 메소드를 사용하면 PHAsset, PHCollection 에서 An ordered list of asset and collection을 가져올 수 있다.

PHFetchOptions

Fetch를 어떻게 할 것인가에 대한 option class이다.


요약 및 정리

PHObject - PHAsset(사진, 비디오 라이브포토 하나하나), PHCollection - PHAssetCollection(앨범) or PHCollectionList(앨범목록)

상위 클래스는 직접 create, use instance 불가. 하위 클래스들을 사용해야함

어떻게 사용? → fetchMethod를 이용해서 retrive해서 사용.

0개의 댓글