Skip to content

Instantly share code, notes, and snippets.

@dfrobison
dfrobison / RemoveDividers.swift
Last active February 8, 2020 17:42
[Remove dividers] Current way of removing the dividing lines on List, Form, etc.
struct Container: View {
init() {
// To remove only extra separators below the list:
UITableView.appearance().tableFooterView = UIView()
// To remove all separators including the actual ones:
UITableView.appearance().separatorStyle = .none
}
@dfrobison
dfrobison / dropDown.swift
Last active February 4, 2020 19:53
[Dropdown menu for SwiftUI] from Kavsoft (https://www.youtube.com/watch?v=CwD4cScGCq8)
struct DropDown: View {
@State var expand = false
var body: some View {
VStack(alignment: .leading, spacing: 18, content: {
HStack {
Text("Expand").fontWeight(.heavy).foregroundColor(.white)
Image(systemName: expand ? "chevron.up" : "chevron.down").resizable().frame(width: 13, height: 6).foregroundColor(.white)
}
.onTapGesture {
@dfrobison
dfrobison / Result.swift
Created February 4, 2020 03:40
[Result’s convenience APIs] from John Sundell (https://www.swiftbysundell.com/tips/result-type-convenience-apis/)
let data: Data = ...
let decoder = JSONDecoder()
// This will create a Result<Model, Error> instance, which will contain
// 'success' if its expression succeeded, and 'failure' if it ended
// up throwing an error:
let result = Result {
try decoder.decode(Model.self, from: data)
}
// Introducing a 'combine' function for applying a value to
// any function or closure:
func combine<A, B>(
_ value: A,
with closure: @escaping (A) -> B
) -> () -> B {
return { closure(value) }
}
// Example