-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from Shopify/sections-rows-duplicates
Supply duplicate keys in exception user info
- Loading branch information
Showing
9 changed files
with
206 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Array+TableSection.swift | ||
// FunctionalTableData | ||
// | ||
// Created by Sherry Shao on 2018-06-14. | ||
// Copyright © 2018 Shopify. All rights reserved. | ||
// | ||
|
||
extension Array where Element: TableSectionType { | ||
func validateKeyUniqueness(senderName: String) { | ||
let sectionKeys = map { $0.key } | ||
if Set(sectionKeys).count != count { | ||
let dupKeys = duplicateKeys() | ||
let reason = "\(senderName) : Duplicate Section keys" | ||
let userInfo: [String: Any] = ["Duplicates": dupKeys] | ||
NSException(name: NSExceptionName.internalInconsistencyException, reason: reason, userInfo: userInfo).raise() | ||
} | ||
|
||
for section in self { | ||
let rowKeys = section.rows.map { $0.key } | ||
if Set(rowKeys).count != section.rows.count { | ||
let dupKeys = section.rows.duplicateKeys() | ||
let reason = "\(senderName) : Duplicate Section.Row keys" | ||
let userInfo: [String: Any] = ["Section": section.key, "Duplicates": dupKeys] | ||
NSException(name: NSExceptionName.internalInconsistencyException, reason: reason, userInfo: userInfo).raise() | ||
} | ||
} | ||
} | ||
} | ||
|
||
private extension Array where Element: Hashable { | ||
func duplicates() -> Set<Element> { | ||
var dups: Set<Element> = [] | ||
var uniques: Set<Element> = [] | ||
forEach { | ||
if uniques.contains($0) { | ||
dups.insert($0) | ||
} else { | ||
uniques.insert($0) | ||
} | ||
} | ||
return dups | ||
} | ||
} | ||
|
||
private extension Array where Element: TableSectionType { | ||
func duplicateKeys() -> Set<String> { | ||
return map { $0.key }.duplicates() | ||
} | ||
} | ||
|
||
private extension Array where Element == CellConfigType { | ||
func duplicateKeys() -> Set<String> { | ||
return map { $0.key }.duplicates() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.