Created
April 1, 2017 21:35
-
-
Save JohnSundell/579a10deb86ef0bbac742dd9a9e986bb to your computer and use it in GitHub Desktop.
Code sample #2 from my Medium post "Namespacing Swift code with nested types"
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
struct Post { | |
class TextFormatter { | |
enum Option { | |
case highlightNames | |
case highlightLinks | |
} | |
private let options: Set<Option> | |
init(options: Set<Option>) { | |
self.options = options | |
} | |
func formatTitle(for post: Post) -> String { | |
return post.title.formatted(withOptions: options) | |
} | |
func formatText(for post: Post) -> String { | |
return post.text.formatted(withOptions: options) | |
} | |
} | |
let id: Int | |
let author: User | |
let title: String | |
let text: String | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment