Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
xx messenger iOS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
xx messenger iOS
Commits
ddc0ffab
Commit
ddc0ffab
authored
2 years ago
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Fix issue with cell building
parent
c474540c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!54
Releasing 1.1.4
,
!51
CollectionView library
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/CollectionView/CellFactory.swift
+6
-3
6 additions, 3 deletions
Sources/CollectionView/CellFactory.swift
Tests/CollectionViewTests/CellFactoryTests.swift
+55
-25
55 additions, 25 deletions
Tests/CollectionViewTests/CellFactoryTests.swift
with
61 additions
and
28 deletions
Sources/CollectionView/CellFactory.swift
+
6
−
3
View file @
ddc0ffab
...
...
@@ -52,9 +52,12 @@ extension CellFactory {
factories
.
forEach
{
$0
.
register
(
in
:
collectionView
)
}
},
build
:
.
init
{
model
,
collectionView
,
indexPath
in
factories
.
lazy
.
compactMap
{
$0
.
build
(
for
:
model
,
in
:
collectionView
,
at
:
indexPath
)
}
.
first
for
factory
in
factories
{
if
let
cell
=
factory
.
build
(
for
:
model
,
in
:
collectionView
,
at
:
indexPath
)
{
return
cell
}
}
return
nil
}
)
}
...
...
This diff is collapsed.
Click to expand it.
Tests/CollectionViewTests/CellFactoryTests.swift
+
55
−
25
View file @
ddc0ffab
import
CustomDump
import
XCTest
@testable
import
CollectionView
final
class
CellFactoryTests
:
XCTestCase
{
func
testCombined
()
{
struct
Cell
:
Equatable
{
var
model
:
Int
var
collectionView
:
UICollectionView
var
indexPath
:
IndexPath
}
var
didRegisterFirst
=
[
UICollectionView
]()
var
didRegisterSecond
=
[
UICollectionView
]()
var
didRegisterThird
=
[
UICollectionView
]()
class
Cell
:
UICollectionViewCell
{
var
collectionView
:
UICollectionView
?
var
indexPath
:
IndexPath
?
}
var
didBuildFirst
=
[
Cell
]()
var
didBuildSecond
=
[
Cell
]()
var
didBuildThird
=
[
Cell
]()
let
factory
=
CellFactory
<
Int
>.
combined
(
.
init
(
register
:
.
init
{
didRegisterFirst
.
append
(
$0
)
},
build
:
.
init
{
model
,
collectionView
,
indexPath
in
guard
model
==
1
else
{
return
nil
}
let
cell
=
Cell
()
cell
.
collectionView
=
collectionView
cell
.
indexPath
=
indexPath
return
cell
didBuildFirst
.
append
(
Cell
(
model
:
model
,
collectionView
:
collectionView
,
indexPath
:
indexPath
))
return
UICollectionViewCell
()
}
),
.
init
(
register
:
.
init
{
didRegisterSecond
.
append
(
$0
)
},
build
:
.
init
{
model
,
collectionView
,
indexPath
in
guard
model
==
2
else
{
return
nil
}
let
cell
=
Cell
()
cell
.
collectionView
=
collectionView
cell
.
indexPath
=
indexPath
return
cell
didBuildSecond
.
append
(
Cell
(
model
:
model
,
collectionView
:
collectionView
,
indexPath
:
indexPath
))
return
UICollectionViewCell
()
}
),
.
init
(
register
:
.
init
{
didRegisterThird
.
append
(
$0
)
},
build
:
.
init
{
model
,
collectionView
,
indexPath
in
guard
model
==
3
else
{
return
nil
}
let
cell
=
Cell
()
cell
.
collectionView
=
collectionView
cell
.
indexPath
=
indexPath
return
cell
didBuildThird
.
append
(
Cell
(
model
:
model
,
collectionView
:
collectionView
,
indexPath
:
indexPath
))
return
UICollectionViewCell
()
}
)
)
...
...
@@ -53,23 +53,53 @@ final class CellFactoryTests: XCTestCase {
XCTAssertEqual
(
didRegisterSecond
,
[
collectionView
])
XCTAssertEqual
(
didRegisterThird
,
[
collectionView
])
let
firstCell
=
factory
.
build
(
for
:
1
,
in
:
collectionView
,
at
:
IndexPath
(
item
:
0
,
section
:
1
))
as?
Cell
let
firstCell
=
factory
.
build
(
for
:
1
,
in
:
collectionView
,
at
:
IndexPath
(
item
:
0
,
section
:
1
))
XCTAssertEqual
(
firstCell
?
.
collectionView
,
collectionView
)
XCTAssertEqual
(
firstCell
?
.
indexPath
,
IndexPath
(
item
:
0
,
section
:
1
))
XCTAssertNotNil
(
firstCell
)
XCTAssertNoDifference
(
didBuildFirst
,
[
Cell
(
model
:
1
,
collectionView
:
collectionView
,
indexPath
:
IndexPath
(
row
:
0
,
section
:
1
)
)])
XCTAssertNoDifference
(
didBuildSecond
,
[])
XCTAssertNoDifference
(
didBuildThird
,
[])
let
secondCell
=
factory
.
build
(
for
:
2
,
in
:
collectionView
,
at
:
IndexPath
(
item
:
2
,
section
:
3
))
as?
Cell
didBuildFirst
=
[]
didBuildSecond
=
[]
didBuildThird
=
[]
let
secondCell
=
factory
.
build
(
for
:
2
,
in
:
collectionView
,
at
:
IndexPath
(
item
:
2
,
section
:
3
))
XCTAssertEqual
(
secondCell
?
.
collectionView
,
collectionView
)
XCTAssertEqual
(
secondCell
?
.
indexPath
,
IndexPath
(
item
:
2
,
section
:
3
))
XCTAssertNotNil
(
secondCell
)
XCTAssertNoDifference
(
didBuildFirst
,
[])
XCTAssertNoDifference
(
didBuildSecond
,
[
Cell
(
model
:
2
,
collectionView
:
collectionView
,
indexPath
:
IndexPath
(
row
:
2
,
section
:
3
)
)])
XCTAssertNoDifference
(
didBuildThird
,
[])
let
thirdCell
=
factory
.
build
(
for
:
3
,
in
:
collectionView
,
at
:
IndexPath
(
item
:
4
,
section
:
5
))
as?
Cell
didBuildFirst
=
[]
didBuildSecond
=
[]
didBuildThird
=
[]
let
thirdCell
=
factory
.
build
(
for
:
3
,
in
:
collectionView
,
at
:
IndexPath
(
item
:
4
,
section
:
5
))
XCTAssertEqual
(
thirdCell
?
.
collectionView
,
collectionView
)
XCTAssertEqual
(
thirdCell
?
.
indexPath
,
IndexPath
(
item
:
4
,
section
:
5
))
XCTAssertNotNil
(
thirdCell
)
XCTAssertNoDifference
(
didBuildFirst
,
[])
XCTAssertNoDifference
(
didBuildSecond
,
[])
XCTAssertNoDifference
(
didBuildThird
,
[
Cell
(
model
:
3
,
collectionView
:
collectionView
,
indexPath
:
IndexPath
(
row
:
4
,
section
:
5
)
)])
didBuildFirst
=
[]
didBuildSecond
=
[]
didBuildThird
=
[]
let
otherCell
=
factory
.
build
(
for
:
4
,
in
:
collectionView
,
at
:
IndexPath
(
item
:
0
,
section
:
0
))
XCTAssertNil
(
otherCell
)
XCTAssertNoDifference
(
didBuildFirst
,
[])
XCTAssertNoDifference
(
didBuildSecond
,
[])
XCTAssertNoDifference
(
didBuildThird
,
[])
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment