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
var body: some View { | |
NavigationView { | |
Form { | |
Section { | |
makeFruitPicker() | |
makePlanetPicker() | |
}.navigationBarTitle("Pickers") | |
} | |
}.navigationViewStyle(StackNavigationViewStyle()) | |
} |
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 SwiftUI | |
struct ContentView: View { | |
@State private var selectedFruit: Fruit = .orange | |
var body: some View { | |
NavigationView { | |
Form { | |
Section { | |
makeFruitPicker() |
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 SwiftUI | |
import UIKit | |
final class BackgroundView: UIView { | |
override init(frame: CGRect) { | |
super.init(frame: .zero) | |
backgroundColor = .systemBackground | |
layer.cornerRadius = 32 | |
layer.borderColor = UIColor.systemBlue.cgColor | |
layer.borderWidth = 14 |
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 SwiftUI | |
final class ContentViewController: UIViewController { | |
override func loadView() { | |
self.view = UIView() | |
self.view.backgroundColor = .systemBackground | |
} | |
override func viewDidLoad() { |
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
extension UIApplicationShortcutItem { | |
enum Action: String { | |
case addPlant | |
case showPlant | |
} | |
} | |
final class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { | |
guard let identifier = UIApplicationShortcutItem.Action(rawValue: shortcutItem.type) else { fatalError("Unknown shortcut") } |
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
func reloadShortcuts() { | |
let context = dependencyContainer.persistentContainer.viewContext | |
let plants = Plant.all(in: context).sorted(by: { $0.name < $1.name }) | |
let items = plants.map({ (plant) -> UIApplicationShortcutItem in | |
return UIApplicationShortcutItem(type: UIApplicationShortcutItem.Action.showPlant.rawValue, | |
localizedTitle: plant.name, | |
localizedSubtitle: nil, | |
icon: UIApplicationShortcutIcon(systemImageName: "leaf.arrow.circlepath"), | |
userInfo: ["id": plant.id] as [String: NSSecureCoding]) | |
}) |
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
<key>UIApplicationShortcutItems</key> | |
<array> | |
<dict> | |
<key>UIApplicationShortcutItemType</key> | |
<string>com.augmentedcode.watermyplants.addplants</string> | |
<key>UIApplicationShortcutItemTitle</key> | |
<string>Add Plant</string> | |
<key>UIApplicationShortcutItemIconType</key> | |
<string>UIApplicationShortcutIconTypeAdd</string> | |
</dict> |
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 var cancellables = [AnyCancellable]() | |
let cancellable = NotificationCenter.default.publisher(for: .NSManagedObjectContextObjectsDidChange, object: managedObjectContext) | |
.compactMap({ ManagedObjectContextChanges<ColorItem>(notification: $0) }).sink { (changes) in | |
print(changes) | |
} | |
cancellables.append(cancellable) | |
struct ManagedObjectContextChanges<T: NSManagedObject> { | |
let inserted: Set<T> |
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
let cancellable = color.publisher(for: \.hex).sink { (string) in | |
print(string) | |
} |
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 Cell: View { | |
@ObservedObject var colorItem: ColorItem | |
var body: some View { | |
HStack { | |
Text(verbatim: colorItem.hex) | |
Spacer() | |
Rectangle().foregroundColor(Color(colorItem.uiColor)).frame(minWidth: 50, maxWidth: 50) | |
} | |
} |