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 SimpleWidget: Widget { | |
| let kind: String = "SimpleWidget" | |
| var body: some WidgetConfiguration { | |
| StaticConfiguration(kind: kind, provider: Provider()) { entry in | |
| PortfolioWidgetEntryView(entry: entry) | |
| } | |
| .configurationDisplayName("Up next…") | |
| .description("Your #1 top-priority item.") | |
| .supportedFamilies([.systemSmall]) |
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 CoreSpotlight | |
| import SwiftUI | |
| struct ContentView: View { | |
| @State private var searchText = "" | |
| @State private var searchResults = [CSSearchableItem]() | |
| @State private var searchQuery: CSSearchQuery? | |
| var body: some View { |
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 Foundation | |
| extension Bundle { | |
| func decode<T: Decodable>(_ type: T.Type, from file: String, dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate, keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys) -> T { | |
| guard let url = self.url(forResource: file, withExtension: nil) else { | |
| fatalError("Failed to locate \(file) in bundle.") | |
| } | |
| guard let data = try? Data(contentsOf: url) else { |
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
| NavigationView { | |
| ResortListView(filteredResorts: filteredResorts) | |
| .searchable(text: $searchText, placement: .navigationBarDrawer(displayMode: .always), | |
| prompt: "Looking for a resort?") { | |
| ForEach(searchResults) { | |
| Text("Are you looking for \($0.name)?").searchCompletion($0.name) | |
| } | |
| } |
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 { | |
| var filteredResorts: [Resort] { | |
| // search result | |
| let searchList = searchResults | |
| ...... | |
| // search within resorts | |
| @State private var searchText = "" |
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 { | |
| enum FilterType { | |
| case abc, country, price | |
| } | |
| @State private var selectedFilter:FilterType = .abc | |
| var filteredResorts: [Resort] { | |
| switch selectedFilter { | |
| case .abc: | |
| print("abc selected") |
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 | |
| class Favorites: ObservableObject { | |
| // user's favorite resorts | |
| private var resorts: Set<String> | |
| // UserDefaults key | |
| private let saveKey = "Favorites" | |
| init() { |
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
| // | |
| // Bundle-Decodable.swift | |
| import Foundation | |
| extension Bundle { | |
| func decode<T: Decodable>(_ file: String) -> T { | |
| guard let url = self.url(forResource: file, withExtension: nil) else { | |
| fatalError("Failed to locate \(file) in bundle.") | |
| } |
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 UserView: View { | |
| var body: some View { | |
| Group { | |
| Text("Name: Ryan") | |
| Text("Second Third") | |
| Text("Devices: MacBook, iPhone") | |
| } | |
| } |
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 UserView: View { | |
| var body: some View { | |
| Group { | |
| Text("Name: Ryan") | |
| Text("Second Third") | |
| Text("Devices: MacBook, iPhone") | |
| } | |
| } |