Skip to content

Commit 7ccbba0

Browse files
committed
Optionals don't need to be explicitely initialized to nil
1 parent 049bd96 commit 7ccbba0

File tree

12 files changed

+346
-241
lines changed

12 files changed

+346
-241
lines changed

CollectionViewCenteredFlowLayout/CollectionViewCenteredFlowLayout.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ open class CollectionViewCenteredFlowLayout: UICollectionViewFlowLayout {
3636
// we group copies of the elements from the same row/column
3737
var representedElements: [UICollectionViewLayoutAttributes] = []
3838
var cells: [[UICollectionViewLayoutAttributes]] = [[]]
39-
var previousFrame: CGRect? = nil
39+
var previousFrame: CGRect?
4040
if scrollDirection == .vertical {
4141
for layoutAttributes in layoutAttributesForElements {
4242
guard layoutAttributes.representedElementKind == nil else {
4343
representedElements.append(layoutAttributes)
4444
continue
4545
}
46+
// copying is required to avoid "UICollectionViewFlowLayout cache mismatched frame"
4647
let currentItemAttributes = layoutAttributes.copy() as! UICollectionViewLayoutAttributes
4748
// if the current frame, once stretched to the full row doesn't intersect the previous frame then they are on different rows
4849
if previousFrame != nil && !currentItemAttributes.frame.intersects(CGRect(x: -.greatestFiniteMagnitude, y: previousFrame!.origin.y, width: .infinity, height: previousFrame!.size.height)) {
@@ -72,6 +73,7 @@ open class CollectionViewCenteredFlowLayout: UICollectionViewFlowLayout {
7273
representedElements.append(layoutAttributes)
7374
continue
7475
}
76+
// copying is required to avoid "UICollectionViewFlowLayout cache mismatched frame"
7577
let currentItemAttributes = layoutAttributes.copy() as! UICollectionViewLayoutAttributes
7678
// if the current frame, once stretched to the full column doesn't intersect the previous frame then they are on different columns
7779
if previousFrame != nil && !currentItemAttributes.frame.intersects(CGRect(x: previousFrame!.origin.x, y: -.greatestFiniteMagnitude, width: previousFrame!.size.width, height: .infinity)) {

Example/CollectionViewCenteredFlowLayout.xcodeproj/project.pbxproj

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
377A00E71EC17905003CC399 /* Frameworks */,
101101
377A00E81EC17905003CC399 /* Resources */,
102102
D61BC8552D3D08F1C98C8F3C /* [CP] Embed Pods Frameworks */,
103-
F70EEE081BE8E98A3F147728 /* [CP] Copy Pods Resources */,
104103
);
105104
buildRules = (
106105
);
@@ -165,13 +164,16 @@
165164
files = (
166165
);
167166
inputPaths = (
167+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
168+
"${PODS_ROOT}/Manifest.lock",
168169
);
169170
name = "[CP] Check Pods Manifest.lock";
170171
outputPaths = (
172+
"$(DERIVED_FILE_DIR)/Pods-CollectionViewCenteredFlowLayout-checkManifestLockResult.txt",
171173
);
172174
runOnlyForDeploymentPostprocessing = 0;
173175
shellPath = /bin/sh;
174-
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
176+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
175177
showEnvVarsInLog = 0;
176178
};
177179
D61BC8552D3D08F1C98C8F3C /* [CP] Embed Pods Frameworks */ = {
@@ -180,30 +182,18 @@
180182
files = (
181183
);
182184
inputPaths = (
185+
"${SRCROOT}/Pods/Target Support Files/Pods-CollectionViewCenteredFlowLayout/Pods-CollectionViewCenteredFlowLayout-frameworks.sh",
186+
"${BUILT_PRODUCTS_DIR}/CollectionViewCenteredFlowLayout/CollectionViewCenteredFlowLayout.framework",
183187
);
184188
name = "[CP] Embed Pods Frameworks";
185189
outputPaths = (
190+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CollectionViewCenteredFlowLayout.framework",
186191
);
187192
runOnlyForDeploymentPostprocessing = 0;
188193
shellPath = /bin/sh;
189194
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CollectionViewCenteredFlowLayout/Pods-CollectionViewCenteredFlowLayout-frameworks.sh\"\n";
190195
showEnvVarsInLog = 0;
191196
};
192-
F70EEE081BE8E98A3F147728 /* [CP] Copy Pods Resources */ = {
193-
isa = PBXShellScriptBuildPhase;
194-
buildActionMask = 2147483647;
195-
files = (
196-
);
197-
inputPaths = (
198-
);
199-
name = "[CP] Copy Pods Resources";
200-
outputPaths = (
201-
);
202-
runOnlyForDeploymentPostprocessing = 0;
203-
shellPath = /bin/sh;
204-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CollectionViewCenteredFlowLayout/Pods-CollectionViewCenteredFlowLayout-resources.sh\"\n";
205-
showEnvVarsInLog = 0;
206-
};
207197
/* End PBXShellScriptBuildPhase section */
208198

209199
/* Begin PBXSourcesBuildPhase section */
@@ -248,15 +238,23 @@
248238
CLANG_CXX_LIBRARY = "libc++";
249239
CLANG_ENABLE_MODULES = YES;
250240
CLANG_ENABLE_OBJC_ARC = YES;
241+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
251242
CLANG_WARN_BOOL_CONVERSION = YES;
243+
CLANG_WARN_COMMA = YES;
252244
CLANG_WARN_CONSTANT_CONVERSION = YES;
245+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
253246
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
254247
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
255248
CLANG_WARN_EMPTY_BODY = YES;
256249
CLANG_WARN_ENUM_CONVERSION = YES;
257250
CLANG_WARN_INFINITE_RECURSION = YES;
258251
CLANG_WARN_INT_CONVERSION = YES;
252+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
253+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
254+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
259255
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
256+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
257+
CLANG_WARN_STRICT_PROTOTYPES = YES;
260258
CLANG_WARN_SUSPICIOUS_MOVE = YES;
261259
CLANG_WARN_UNREACHABLE_CODE = YES;
262260
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -299,15 +297,23 @@
299297
CLANG_CXX_LIBRARY = "libc++";
300298
CLANG_ENABLE_MODULES = YES;
301299
CLANG_ENABLE_OBJC_ARC = YES;
300+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
302301
CLANG_WARN_BOOL_CONVERSION = YES;
302+
CLANG_WARN_COMMA = YES;
303303
CLANG_WARN_CONSTANT_CONVERSION = YES;
304+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
304305
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
305306
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
306307
CLANG_WARN_EMPTY_BODY = YES;
307308
CLANG_WARN_ENUM_CONVERSION = YES;
308309
CLANG_WARN_INFINITE_RECURSION = YES;
309310
CLANG_WARN_INT_CONVERSION = YES;
311+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
312+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
313+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
310314
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
315+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
316+
CLANG_WARN_STRICT_PROTOTYPES = YES;
311317
CLANG_WARN_SUSPICIOUS_MOVE = YES;
312318
CLANG_WARN_UNREACHABLE_CODE = YES;
313319
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;

Example/CollectionViewCenteredFlowLayout.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ EXTERNAL SOURCES:
99
:path: ".."
1010

1111
SPEC CHECKSUMS:
12-
CollectionViewCenteredFlowLayout: b95892ba0c0d047e348eb0b64c4ee5b52ff0bf9b
12+
CollectionViewCenteredFlowLayout: 9c9dbe7f28dbacadea3330cf7bcd2f26b7ea8836
1313

1414
PODFILE CHECKSUM: 3fa6777a7a1e9edde6c8ce74fd0509ef089b71f2
1515

16-
COCOAPODS: 1.2.1
16+
COCOAPODS: 1.5.3

Example/Pods/Manifest.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)