Skip to content

Commit 08cb9b7

Browse files
cburrowsthomasvl
authored andcommitted
Correct Swift 4.1 build break (#828)
It looks like #822 added a call to Array.firstIndex, which was only added in Swift 4.2. So builds are broken with Swift 4.1. This adds firstIndex for Swifts prior to 4.2 to fix them.
1 parent eed1b8e commit 08cb9b7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Sources/SwiftProtobufPluginLibrary/Array+Extensions.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,18 @@ extension Array {
3535
}
3636
}
3737
}
38+
39+
#if !swift(>=4.2)
40+
extension Array {
41+
func firstIndex(where predicate: (Element) throws -> Bool) rethrows -> Int? {
42+
var i = self.startIndex
43+
while i < self.endIndex {
44+
if try predicate(self[i]) {
45+
return i
46+
}
47+
self.formIndex(after: &i)
48+
}
49+
return nil
50+
}
51+
}
52+
#endif // !swift(>=4.2)

0 commit comments

Comments
 (0)