Instantly share code, notes, and snippets.
Freelance iOS developer.
- Utrecht, Netherlands
- https://sjoerdtieleman.nl/
tieleman
/ ButtonView.swift
Created
April 22, 2020 08:25
This file contains hidden or 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
private func buildComplexButton() -> some View { | |
if someConditional { | |
return Button("Press me") { | |
// do something | |
} | |
} else { | |
return Button("No, press me") { | |
// do something else | |
} | |
} |
tieleman
/ ButtonViewComplex.swift
Created
April 22, 2020 09:10
This file contains hidden or 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
private func buildComplexButton() -> some View { | |
if someConditional { | |
return Button(action: { /* do something */ }) { | |
Text("1") | |
} | |
} else { | |
return Button(action: { /* do something else */ }) { | |
Image(systemName: "faceid") | |
} | |
} |
tieleman
/ ButtonViewGroup.swift
Created
April 23, 2020 11:26
This file contains hidden or 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
private func buildComplexButton() -> some View { | |
Group { | |
if someConditional { | |
Button(action: { /* do something */ }) { | |
Text("1") | |
} | |
} else { | |
Button(action: { /* do something else */ }) { | |
Image(systemName: "faceid") | |
} |
tieleman
/ ButtonViewAnyView.swift
Created
April 23, 2020 11:38
This file contains hidden or 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
private func buildComplexButton() -> some View { | |
if someConditional { | |
return AnyView(Button(action: { /* do something */ }) { | |
Text("1") | |
}) | |
} else { | |
return AnyView(Button(action: { /* do something else */ }) { | |
Image(systemName: "faceid") | |
}) | |
} |
tieleman
/ ButtonViewAnyViewExtension.swift
Created
April 23, 2020 11:45
This file contains hidden or 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
// Put in top level file scope | |
extension View { | |
func eraseToAnyView() -> AnyView { | |
AnyView(self) | |
} | |
} | |
private func buildComplexButton() -> some View { | |
if someConditional { | |
return Button(action: { /* do something */ }) { |
tieleman
/ AuthorViewModel.swift
Last active
August 4, 2020 09:32
This file contains hidden or 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 Author { | |
var firstName: String | |
var lastName: String | |
var booksWritten: Int | |
} | |
class AuthorViewModel { | |
private let service = AuthorWebService() | |
func allAuthors() -> [Author] { |
tieleman
/ AuthorViewModel.swift
Last active
August 4, 2020 09:32
This file contains hidden or 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
protocol AuthorServiceProtocol { | |
func fetchAllAuthors() -> [Author] | |
} | |
class AuthorWebService: AuthorServiceProtocol { | |
func fetchAllAuthors() -> [Author] { | |
// fetch and return authors | |
} | |
} |
tieleman
/ AuthorViewModelTests.swift
Last active
August 4, 2020 09:31
This file contains hidden or 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
class FakeAuthorService: AuthorServiceProtocol { | |
func fetchAllAuthors() -> [Author] { | |
[ | |
Author(firstName: "Frank", lastName: "Herbert", booksWritten: 27), | |
Author(firstName: "Roald", lastName: "Dahl", booksWritten: 19), | |
Author(firstName: "Haruki", lastName: "Marukami", booksWritten: 14) | |
] | |
} | |
} |
OlderNewer