Skip to content

Commit

Permalink
Merge pull request #32 from robbiet480/patch-1
Browse files Browse the repository at this point in the history
Add CaseIterable to OpenGraphMetadata
  • Loading branch information
satoshi-takano committed Nov 1, 2018
2 parents 873f0b3 + 997b394 commit 143eafa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode9
osx_image: xcode10

xcode_project: OpenGraph.xcodeproj
xcode_scheme: OpenGraph
Expand All @@ -8,4 +8,4 @@ before_install:
- carthage bootstrap

script:
- xcodebuild build-for-testing test-without-building -project OpenGraph.xcodeproj -scheme OpenGraph -configuration Release ENABLE_TESTABILITY=YES
- xcodebuild build-for-testing test-without-building -project OpenGraph.xcodeproj -scheme OpenGraph -configuration Release ENABLE_TESTABILITY=YES
29 changes: 27 additions & 2 deletions OpenGraph/OpenGraphMetadata.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public enum OpenGraphMetadata: String {
public enum OpenGraphMetadata: String, CaseIterable {
// Basic Metadata
case title
case type
Expand Down Expand Up @@ -62,4 +62,29 @@ public enum OpenGraphMetadata: String {
case profileLastName = "profile:lastName"
case profileUsername = "profile:username"
case profileGender = "profile:gender"
}
}

#if !swift(>=4.2)
public protocol CaseIterable {
associatedtype AllCases: Collection where AllCases.Element == Self
static var allCases: AllCases { get }
}
extension CaseIterable where Self: Hashable {
static var allCases: [Self] {
return [Self](AnySequence { () -> AnyIterator<Self> in
var raw = 0
var first: Self?
return AnyIterator {
let current = withUnsafeBytes(of: &raw) { $0.load(as: Self.self) }
if raw == 0 {
first = current
} else if current == first {
return nil
}
raw += 1
return current
}
})
}
}
#endif

0 comments on commit 143eafa

Please sign in to comment.