View content.json
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
{ | |
"content": [ | |
{ | |
"type": "header", | |
"title": "Hello World", | |
"level": 2 | |
}, | |
{ | |
"type": "paragraph", | |
"text": "Blah blah blah" |
View types.swift
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 Content: Codable { | |
let content: [Element] | |
enum Element: Codable { | |
case header(Header) | |
case paragraph(Paragraph) | |
case footer(Footer) | |
struct Header: Codable { | |
let title: String |
View BaseContent.swift
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 BaseContent: Codable { | |
let type: ContentType | |
enum ContentType: String, Codable { | |
case header | |
case paragraph | |
case footer | |
} | |
enum CodingKeys: String, CodingKey { |
View init.swift
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
init(from decoder: Decoder) throws { | |
let baseContainer = try decoder.container(keyedBy: BaseContent.CodingKeys.self) | |
let type = try baseContainer.decode(BaseContent.ContentType.self, forKey: .type) | |
let container = try decoder.singleValueContainer() | |
switch type { | |
case .header: | |
self = .header(try container.decode(Header.self)) | |
case .paragraph: |
View Content.swift
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 Content: Codable { | |
let content: [Element] | |
enum Element: Codable { | |
case header(Header) | |
case paragraph(Paragraph) | |
case footer(Footer) | |
struct Header: Codable { | |
let title: String |
View UsualCodable.swift
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
import Foundation | |
struct Example: Codable { | |
let id: Int | |
var text: String | |
} | |
let json = """ | |
{ | |
"id": 1, |
View hooray.py
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
l = [0, 1, 2, 3, 4, 5, 6] | |
# w/ map & filter | |
>>> list(map(lambda a: a * 2, filter(lambda a: a > 2, l))) | |
[6, 8, 10, 12] | |
# w/ generator | |
>>> list(a * 2 for a in l if a > 2) | |
[6, 8, 10, 12] |
View text.txt
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
Hello world, my name is [Emma](https://emma.sh). Sometimes I write Swift code. |
View LinkAndText.swift
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 LinkAndText: View { | |
var body: some View { | |
Text("Hello world, my name is ") | |
Link("Emma", destination: URL(string: "https://emma.sh")!) | |
Text(". Sometimes I write Swift code.") | |
} | |
} |
View LinkAndTextHStack.swift
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 LinkAndText: View { | |
var body: some View { | |
HStack { | |
Text("Hello world, my name is ") | |
Link("Emma", destination: URL(string: "https://emma.sh")!) | |
Text(". Sometimes I write Swift code.") | |
} | |
} | |
} |
OlderNewer