Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
5c14de2d
Commit
5c14de2d
authored
Aug 03, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue-479: added helper methods to simplify fetch requests in PhotoLibrary
parent
2f4ac3e2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
100 deletions
+118
-100
Sources/iOS/PhotoLibrary.swift
+118
-100
No files found.
Sources/iOS/PhotoLibrary.swift
View file @
5c14de2d
...
@@ -437,24 +437,40 @@ extension PhotoLibrary {
...
@@ -437,24 +437,40 @@ extension PhotoLibrary {
/// PHCollection.
/// PHCollection.
extension
PhotoLibrary
{
extension
PhotoLibrary
{
/**
/**
Fetch PHCollection based on a type and subtype.
Fetches PHCollections in a given PHCollectionList.
- Parameter in collectionList: A PHCollectionList.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public
func
fetchCollections
(
in
collectionList
:
PHCollectionList
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollection
],
PHFetchResult
<
PHCollection
>
)
->
Void
)
{
fetchCollections
(
fetchResult
:
PHCollection
.
fetchCollections
(
in
:
collectionList
,
options
:
options
),
completion
:
completion
)
}
/**
Fetches PHCollections based on a type and subtype.
- Parameter with type: A PHCollectionListType.
- Parameter with type: A PHCollectionListType.
- Parameter subtype: A PHCollectionListSubtype.
- Parameter subtype: A PHCollectionListSubtype.
- Parameter options: An optional PHFetchOptions object.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
- Parameter completion: A completion callback.
*/
*/
public
func
fetchTopLevelUserCollections
(
with
options
:
PHFetchOptions
?,
completion
:
([
PHCollection
],
PHFetchResult
<
PHCollection
>
)
->
Void
)
{
public
func
fetchTopLevelUserCollections
(
with
options
:
PHFetchOptions
?,
completion
:
([
PHCollection
],
PHFetchResult
<
PHCollection
>
)
->
Void
)
{
fetchCollections
(
fetchResult
:
PHCollection
.
fetchTopLevelUserCollections
(
with
:
nil
),
completion
:
completion
)
}
/**
Fetches the PHCollections for a given PHFetchResult<PHCollection>.
- Parameter fetchResult: A PHFetchResult<PHCollection>.
- Parameter completion: A completion block.
*/
private
func
fetchCollections
(
fetchResult
:
PHFetchResult
<
PHCollection
>
,
completion
:
([
PHCollection
],
PHFetchResult
<
PHCollection
>
)
->
Void
)
{
var
collections
=
[
PHCollection
]()
var
collections
=
[
PHCollection
]()
let
fetchResult
=
PHCollection
.
fetchTopLevelUserCollections
(
with
:
nil
)
defer
{
fetchResult
.
enumerateObjects
({
(
collection
,
_
,
_
)
in
DispatchQueue
.
main
.
async
{
[
collections
=
collections
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
collections
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
(
options
:
[
.
concurrent
])
{
(
collection
,
_
,
_
)
in
collections
.
append
(
collection
)
collections
.
append
(
collection
)
})
DispatchQueue
.
main
.
async
{
[
collections
=
collections
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
collections
,
fetchResult
)
}
}
}
}
}
}
...
@@ -471,18 +487,7 @@ extension PhotoLibrary {
...
@@ -471,18 +487,7 @@ extension PhotoLibrary {
- Parameter completion: A completion callback.
- Parameter completion: A completion callback.
*/
*/
public
func
fetchCollectionListsContaining
(
_
collection
:
PHCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
public
func
fetchCollectionListsContaining
(
_
collection
:
PHCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
var
lists
=
[
PHCollectionList
]()
fetchCollectionLists
(
fetchResult
:
PHCollectionList
.
fetchCollectionListsContaining
(
collection
,
options
:
options
),
completion
:
completion
)
let
fetchResult
=
PHCollectionList
.
fetchCollectionListsContaining
(
collection
,
options
:
options
)
defer
{
DispatchQueue
.
main
.
async
{
[
lists
=
lists
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
lists
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
({
(
list
,
_
,
_
)
in
lists
.
append
(
list
)
})
}
}
/**
/**
...
@@ -493,18 +498,7 @@ extension PhotoLibrary {
...
@@ -493,18 +498,7 @@ extension PhotoLibrary {
- Parameter completion: A completion callback.
- Parameter completion: A completion callback.
*/
*/
public
func
fetchCollectionList
(
with
type
:
PHCollectionListType
,
subtype
:
PHCollectionListSubtype
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
public
func
fetchCollectionList
(
with
type
:
PHCollectionListType
,
subtype
:
PHCollectionListSubtype
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
var
lists
=
[
PHCollectionList
]()
fetchCollectionLists
(
fetchResult
:
PHCollectionList
.
fetchCollectionLists
(
with
:
type
,
subtype
:
subtype
,
options
:
options
),
completion
:
completion
)
let
fetchResult
=
PHCollectionList
.
fetchCollectionLists
(
with
:
type
,
subtype
:
subtype
,
options
:
options
)
defer
{
DispatchQueue
.
main
.
async
{
[
lists
=
lists
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
lists
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
({
(
list
,
_
,
_
)
in
lists
.
append
(
list
)
})
}
}
/**
/**
...
@@ -517,18 +511,7 @@ extension PhotoLibrary {
...
@@ -517,18 +511,7 @@ extension PhotoLibrary {
- Parameter completion: A completion callback.
- Parameter completion: A completion callback.
*/
*/
public
func
fetchCollectionLists
(
withLocalIdentifiers
identifiers
:
[
String
],
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
public
func
fetchCollectionLists
(
withLocalIdentifiers
identifiers
:
[
String
],
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
var
lists
=
[
PHCollectionList
]()
fetchCollectionLists
(
fetchResult
:
PHCollectionList
.
fetchCollectionLists
(
withLocalIdentifiers
:
identifiers
,
options
:
options
),
completion
:
completion
)
let
fetchResult
=
PHCollectionList
.
fetchCollectionLists
(
withLocalIdentifiers
:
identifiers
,
options
:
options
)
defer
{
DispatchQueue
.
main
.
async
{
[
lists
=
lists
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
lists
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
({
(
list
,
_
,
_
)
in
lists
.
append
(
list
)
})
}
}
/**
/**
...
@@ -540,19 +523,8 @@ extension PhotoLibrary {
...
@@ -540,19 +523,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
- Parameter completion: A completion callback.
*/
*/
public
class
func
fetchCollectionLists
(
with
collectionListType
:
PHCollectionListType
,
subtype
:
PHCollectionListSubtype
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
public
func
fetchCollectionLists
(
with
collectionListType
:
PHCollectionListType
,
subtype
:
PHCollectionListSubtype
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
var
lists
=
[
PHCollectionList
]()
fetchCollectionLists
(
fetchResult
:
PHCollectionList
.
fetchCollectionLists
(
with
:
collectionListType
,
subtype
:
subtype
,
options
:
options
),
completion
:
completion
)
let
fetchResult
=
PHCollectionList
.
fetchCollectionLists
(
with
:
collectionListType
,
subtype
:
subtype
,
options
:
options
)
defer
{
DispatchQueue
.
main
.
async
{
[
lists
=
lists
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
lists
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
({
(
list
,
_
,
_
)
in
lists
.
append
(
list
)
})
}
}
/**
/**
...
@@ -562,19 +534,8 @@ extension PhotoLibrary {
...
@@ -562,19 +534,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
- Parameter completion: A completion callback.
*/
*/
public
class
func
fetchMomentLists
(
with
momentListSubtype
:
PHCollectionListSubtype
,
containingMoment
moment
:
PHAssetCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
public
func
fetchMomentLists
(
with
momentListSubtype
:
PHCollectionListSubtype
,
containingMoment
moment
:
PHAssetCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
var
lists
=
[
PHCollectionList
]()
fetchCollectionLists
(
fetchResult
:
PHCollectionList
.
fetchMomentLists
(
with
:
momentListSubtype
,
containingMoment
:
moment
,
options
:
options
),
completion
:
completion
)
let
fetchResult
=
PHCollectionList
.
fetchMomentLists
(
with
:
momentListSubtype
,
containingMoment
:
moment
,
options
:
options
)
defer
{
DispatchQueue
.
main
.
async
{
[
lists
=
lists
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
lists
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
({
(
list
,
_
,
_
)
in
lists
.
append
(
list
)
})
}
}
/**
/**
...
@@ -584,18 +545,24 @@ extension PhotoLibrary {
...
@@ -584,18 +545,24 @@ extension PhotoLibrary {
- Parameter completion: A completion callback.
- Parameter completion: A completion callback.
*/
*/
public
func
fetchMomentLists
(
with
momentListSubtype
:
PHCollectionListSubtype
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
public
func
fetchMomentLists
(
with
momentListSubtype
:
PHCollectionListSubtype
,
options
:
PHFetchOptions
?,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
fetchCollectionLists
(
fetchResult
:
PHCollectionList
.
fetchMomentLists
(
with
:
momentListSubtype
,
options
:
options
),
completion
:
completion
)
}
/**
Fetches the PHCollectionLists for a given PHFetchResult<PHCollectionList>.
- Parameter fetchResult: A PHFetchResult<PHCollectionList>.
- Parameter completion: A completion block.
*/
private
func
fetchCollectionLists
(
fetchResult
:
PHFetchResult
<
PHCollectionList
>
,
completion
:
([
PHCollectionList
],
PHFetchResult
<
PHCollectionList
>
)
->
Void
)
{
var
lists
=
[
PHCollectionList
]()
var
lists
=
[
PHCollectionList
]()
let
fetchResult
=
PHCollectionList
.
fetchMomentLists
(
with
:
momentListSubtype
,
options
:
options
)
defer
{
DispatchQueue
.
main
.
async
{
[
lists
=
lists
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
lists
,
fetchResult
)
}
}
fetchResult
.
enumerateObjects
({
(
list
,
_
,
_
)
in
fetchResult
.
enumerateObjects
({
(
list
,
_
,
_
)
in
lists
.
append
(
list
)
lists
.
append
(
list
)
})
})
DispatchQueue
.
main
.
async
{
[
lists
=
lists
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
lists
,
fetchResult
)
}
}
}
}
}
...
@@ -608,22 +575,58 @@ extension PhotoLibrary {
...
@@ -608,22 +575,58 @@ extension PhotoLibrary {
- Parameter completion: A completion block.
- Parameter completion: A completion block.
*/
*/
public
func
fetchAssets
(
in
assetCollection
:
PHAssetCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
public
func
fetchAssets
(
in
assetCollection
:
PHAssetCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
var
fetchResult
:
PHFetchResult
<
PHAsset
>!
fetchAssets
(
fetchResult
:
PHAsset
.
fetchAssets
(
in
:
assetCollection
,
options
:
options
),
completion
:
completion
)
var
assets
=
[
PHAsset
]()
}
defer
{
/**
DispatchQueue
.
main
.
async
{
[
assets
=
assets
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
Fetch the PHAssets with a given Array of identifiers.
completion
(
assets
,
fetchResult
!
)
- Parameter withLocalIdentifiers identifiers: A Array of
}
String identifiers.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public
func
fetchAssets
(
withLocalIdentifiers
identifiers
:
[
String
],
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
fetchAssets
(
fetchResult
:
PHAsset
.
fetchAssets
(
withLocalIdentifiers
:
identifiers
,
options
:
options
),
completion
:
completion
)
}
/**
Fetch key assets.
- Parameter in assetCollection: A PHAssetCollection.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
- Returns: An optional PHFetchResult<PHAsset> object.
*/
public
func
fetchKeyAssets
(
in
assetCollection
:
PHAssetCollection
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
->
PHFetchResult
<
PHAsset
>
?
{
guard
let
fetchResult
=
PHAsset
.
fetchKeyAssets
(
in
:
assetCollection
,
options
:
options
)
else
{
return
nil
}
}
fetchAssets
(
fetchResult
:
fetchResult
,
completion
:
completion
)
fetchResult
=
PHAsset
.
fetchAssets
(
in
:
assetCollection
,
options
:
options
)
return
fetchResult
}
fetchResult
.
enumerateObjects
({
(
asset
,
_
,
_
)
in
assets
.
append
(
asset
)
/**
})
Fetch a burst asset with a given burst identifier.
- Parameter withBurstIdentifier burstIdentifier: A
PHAssetCollection.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public
func
fetchAssets
(
withBurstIdentifier
burstIdentifier
:
String
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
fetchAssets
(
fetchResult
:
PHAsset
.
fetchAssets
(
withBurstIdentifier
:
burstIdentifier
,
options
:
options
),
completion
:
completion
)
}
}
/**
Fetches PHAssetSourceTypeUserLibrary assets by default (use
includeAssetSourceTypes option to override).
- Parameter with options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public
func
fetchAssets
(
with
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
fetchAssets
(
fetchResult
:
PHAsset
.
fetchAssets
(
with
:
options
),
completion
:
completion
)
}
/**
/**
Fetch the PHAssets with a given media type.
Fetch the PHAssets with a given media type.
- Parameter in mediaType: A PHAssetMediaType.
- Parameter in mediaType: A PHAssetMediaType.
...
@@ -631,20 +634,35 @@ extension PhotoLibrary {
...
@@ -631,20 +634,35 @@ extension PhotoLibrary {
- Parameter completion: A completion block.
- Parameter completion: A completion block.
*/
*/
public
func
fetchAssets
(
with
mediaType
:
PHAssetMediaType
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
public
func
fetchAssets
(
with
mediaType
:
PHAssetMediaType
,
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
var
fetchResult
:
PHFetchResult
<
PHAsset
>!
fetchAssets
(
fetchResult
:
PHAsset
.
fetchAssets
(
with
:
mediaType
,
options
:
options
),
completion
:
completion
)
}
/**
AssetURLs are URLs retrieved from ALAsset's
ALAssetPropertyAssetURL.
- Parameter withALAssetURLs assetURLs: A PHAssetMediaType.
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public
func
fetchAssets
(
withALAssetURLs
assetURLs
:
[
URL
],
options
:
PHFetchOptions
?,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
fetchAssets
(
fetchResult
:
PHAsset
.
fetchAssets
(
withALAssetURLs
:
assetURLs
,
options
:
options
),
completion
:
completion
)
}
/**
Fetches the PHAssets for a given PHFetchResult<PHAsset>.
- Parameter fetchResult: A PHFetchResult<PHAsset>.
- Parameter completion: A completion block.
*/
private
func
fetchAssets
(
fetchResult
:
PHFetchResult
<
PHAsset
>
,
completion
:
([
PHAsset
],
PHFetchResult
<
PHAsset
>
)
->
Void
)
{
var
assets
=
[
PHAsset
]()
var
assets
=
[
PHAsset
]()
defer
{
DispatchQueue
.
main
.
async
{
[
assets
=
assets
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
assets
,
fetchResult
!
)
}
}
fetchResult
=
PHAsset
.
fetchAssets
(
with
:
mediaType
,
options
:
options
)
fetchResult
.
enumerateObjects
({
(
asset
,
_
,
_
)
in
fetchResult
.
enumerateObjects
({
(
asset
,
_
,
_
)
in
assets
.
append
(
asset
)
assets
.
append
(
asset
)
})
})
DispatchQueue
.
main
.
async
{
[
assets
=
assets
,
fetchResult
=
fetchResult
,
completion
=
completion
]
in
completion
(
assets
,
fetchResult
)
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment