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
GitLab 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
Jul 18, 2022
by
Dariusz Rybicki
Browse files
Options
Downloads
Patches
Plain Diff
Fix issue with cell building
parent
c474540c
No related branches found
No related tags found
2 merge requests
!54
Releasing 1.1.4
,
!51
CollectionView library
Changes
2
Show 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 {
...
@@ -52,9 +52,12 @@ extension CellFactory {
factories
.
forEach
{
$0
.
register
(
in
:
collectionView
)
}
factories
.
forEach
{
$0
.
register
(
in
:
collectionView
)
}
},
},
build
:
.
init
{
model
,
collectionView
,
indexPath
in
build
:
.
init
{
model
,
collectionView
,
indexPath
in
factories
.
lazy
for
factory
in
factories
{
.
compactMap
{
$0
.
build
(
for
:
model
,
in
:
collectionView
,
at
:
indexPath
)
}
if
let
cell
=
factory
.
build
(
for
:
model
,
in
:
collectionView
,
at
:
indexPath
)
{
.
first
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
import
XCTest
@testable
import
CollectionView
@testable
import
CollectionView
final
class
CellFactoryTests
:
XCTestCase
{
final
class
CellFactoryTests
:
XCTestCase
{
func
testCombined
()
{
func
testCombined
()
{
struct
Cell
:
Equatable
{
var
model
:
Int
var
collectionView
:
UICollectionView
var
indexPath
:
IndexPath
}
var
didRegisterFirst
=
[
UICollectionView
]()
var
didRegisterFirst
=
[
UICollectionView
]()
var
didRegisterSecond
=
[
UICollectionView
]()
var
didRegisterSecond
=
[
UICollectionView
]()
var
didRegisterThird
=
[
UICollectionView
]()
var
didRegisterThird
=
[
UICollectionView
]()
class
Cell
:
UICollectionViewCell
{
var
didBuildFirst
=
[
Cell
]()
var
collectionView
:
UICollectionView
?
var
didBuildSecond
=
[
Cell
]()
var
indexPath
:
IndexPath
?
var
didBuildThird
=
[
Cell
]()
}
let
factory
=
CellFactory
<
Int
>.
combined
(
let
factory
=
CellFactory
<
Int
>.
combined
(
.
init
(
.
init
(
register
:
.
init
{
didRegisterFirst
.
append
(
$0
)
},
register
:
.
init
{
didRegisterFirst
.
append
(
$0
)
},
build
:
.
init
{
model
,
collectionView
,
indexPath
in
build
:
.
init
{
model
,
collectionView
,
indexPath
in
guard
model
==
1
else
{
return
nil
}
guard
model
==
1
else
{
return
nil
}
let
cell
=
Cell
()
didBuildFirst
.
append
(
Cell
(
model
:
model
,
collectionView
:
collectionView
,
indexPath
:
indexPath
))
cell
.
collectionView
=
collectionView
return
UICollectionViewCell
()
cell
.
indexPath
=
indexPath
return
cell
}
}
),
),
.
init
(
.
init
(
register
:
.
init
{
didRegisterSecond
.
append
(
$0
)
},
register
:
.
init
{
didRegisterSecond
.
append
(
$0
)
},
build
:
.
init
{
model
,
collectionView
,
indexPath
in
build
:
.
init
{
model
,
collectionView
,
indexPath
in
guard
model
==
2
else
{
return
nil
}
guard
model
==
2
else
{
return
nil
}
let
cell
=
Cell
()
didBuildSecond
.
append
(
Cell
(
model
:
model
,
collectionView
:
collectionView
,
indexPath
:
indexPath
))
cell
.
collectionView
=
collectionView
return
UICollectionViewCell
()
cell
.
indexPath
=
indexPath
return
cell
}
}
),
),
.
init
(
.
init
(
register
:
.
init
{
didRegisterThird
.
append
(
$0
)
},
register
:
.
init
{
didRegisterThird
.
append
(
$0
)
},
build
:
.
init
{
model
,
collectionView
,
indexPath
in
build
:
.
init
{
model
,
collectionView
,
indexPath
in
guard
model
==
3
else
{
return
nil
}
guard
model
==
3
else
{
return
nil
}
let
cell
=
Cell
()
didBuildThird
.
append
(
Cell
(
model
:
model
,
collectionView
:
collectionView
,
indexPath
:
indexPath
))
cell
.
collectionView
=
collectionView
return
UICollectionViewCell
()
cell
.
indexPath
=
indexPath
return
cell
}
}
)
)
)
)
...
@@ -53,23 +53,53 @@ final class CellFactoryTests: XCTestCase {
...
@@ -53,23 +53,53 @@ final class CellFactoryTests: XCTestCase {
XCTAssertEqual
(
didRegisterSecond
,
[
collectionView
])
XCTAssertEqual
(
didRegisterSecond
,
[
collectionView
])
XCTAssertEqual
(
didRegisterThird
,
[
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
)
XCTAssertNotNil
(
firstCell
)
XCTAssertEqual
(
firstCell
?
.
indexPath
,
IndexPath
(
item
:
0
,
section
:
1
))
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
)
XCTAssertNotNil
(
secondCell
)
XCTAssertEqual
(
secondCell
?
.
indexPath
,
IndexPath
(
item
:
2
,
section
:
3
))
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
)
XCTAssertNotNil
(
thirdCell
)
XCTAssertEqual
(
thirdCell
?
.
indexPath
,
IndexPath
(
item
:
4
,
section
:
5
))
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
))
let
otherCell
=
factory
.
build
(
for
:
4
,
in
:
collectionView
,
at
:
IndexPath
(
item
:
0
,
section
:
0
))
XCTAssertNil
(
otherCell
)
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