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
extension View { | |
func minimumPadding(edges: Edge.Set = .all, _ length: CGFloat = 8) -> some View { | |
GeometryReader { geo in | |
padding(.bottom, edges.contains(.bottom) ? max(length, geo.safeAreaInsets.bottom) : 0) | |
.padding(.top, edges.contains(.top) ? max(length, geo.safeAreaInsets.top) : 0) | |
.padding(.leading, edges.contains(.leading) ? max(length, geo.safeAreaInsets.leading) : 0) | |
.padding(.trailing, edges.contains(.trailing) ? max(length, geo.safeAreaInsets.trailing) : 0) | |
.ignoresSafeArea(edges: edges) | |
} | |
} |
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 | |
extension Decodable where Self: Encodable { | |
/// Creates a new instance and changes the value for the provided key. | |
/// | |
/// - Parameters: | |
/// - key: The key path to the property that you want to modify. | |
/// Use period to separate levels and [] for indexes. | |
/// Examples: "id", "name.firstName", "children[2].name.firstName" | |
/// |
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
// How to use: | |
struct YourView_Previews: PreviewProvider { | |
static var previews: some View { | |
YourView() | |
.makePreviews() | |
} | |
} |
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
extension Optional { | |
func `let`<T>(_ transform: (Wrapped) -> T?) -> T? { | |
if case .some(let value) = self { | |
return transform(value) | |
} | |
return nil | |
} | |
} |
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 RxSwift | |
extension Observable where Element: OptionalType { | |
func ignoreNil() -> Observable<Element.T> { | |
filter { $0.optional != nil }.map { $0.optional! } | |
} | |
} | |