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
import SwiftUIX | |
struct Friend: Identifiable { // Example model | |
let id: UUID = .init() | |
let name: String | |
} | |
struct ContentView: View { | |
@State var friends: [Friend] = [ | |
.init(name: "Gary"), |
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
// ... | |
List(friends | |
.filter { | |
search( | |
needle: searchText.lowercased(), | |
haystack: $0.name.lowercased() | |
) | |
} | |
) | |
// ... |
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
typealias Predicate<Element> = (Element) -> Bool | |
func ==<Element>(lhs: KeyPath<Element, String>, rhs: String) -> Predicate<Element> { // overload == | |
return { element in | |
guard !rhs.isEmpty else { return true } // make sure not empty | |
return search( | |
needle: rhs.lowercased(), // search | |
haystack: element[keyPath: lhs].lowercased() // value for keypath | |
) | |
} |
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
import SwiftUIX | |
import Introspect | |
var body: some View { | |
NavigationView { | |
// ... | |
.onTapGesture { | |
print(friend.name) | |
Keyboard.main.dismiss() // inactive | |
} |
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 ContentView: View { | |
@State var isPresented: Bool = false | |
var body: some View { | |
Button(action: {}, label: { | |
Text("Present Bottom Sheet") | |
.padding() | |
}) | |
.background(Color.blue) | |
.foregroundColor(.white) |
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
import logo from "./logo.svg"; | |
import "./App.css"; | |
import styled from "styled-components"; | |
function App() { | |
return ( | |
<Container> | |
<WrapperCard> | |
<Card></Card> | |
<Card></Card> |
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
import styled from 'styled-components'; | |
const Container = styled.div` | |
background: #36393e; | |
display: flex; | |
justify-content: center; // 1 | |
flex-flow: column wrap; // 2 | |
width: 100%; | |
height: 100%; |
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
const Header = styled.div` // 1 | |
height: 100px; | |
width: 100%; | |
background: #fff; | |
display: flex; // 2 | |
justify-content: center; | |
`; | |
function App() { | |
return ( |
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
import UIKit | |
import Combine | |
import PlaygroundSupport | |
let label = UILabel(frame: .init(origin: .zero, size: CGSize(width: 100, height: 100))) | |
let url = URL(string: "https://api.mocki.io/v1/aebff128")! | |
var cancellables = Set<AnyCancellable>() | |
URLSession | |
.shared |
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
// Create passthrough subject | |
let todoSubject = PassthroughSubject<Todo, Never>() | |
// Release subscription from memory when done | |
var cancellable: AnyCancellable? | |
// Subscribe to updates | |
cancellable = todoSubject | |
.sink { todo in | |
print("New todo to add to table view:", todo.task) |