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 func setDateFromSelection() { | |
| let monthNumber = getMonthNumberFromName(name: month) | |
| let timeComponents = Calendar.current.dateComponents( | |
| [.hour, .minute, .second, .nanosecond], from: selectedDate) | |
| let dateComponents = DateComponents( | |
| year: year, | |
| month: monthNumber, | |
| day: day, | |
| hour: timeComponents.hour, |
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
| // | |
| // DateUtil.swift | |
| // DrinkSum | |
| // | |
| // Created by Greg Eales on 5/11/20. | |
| // | |
| import Foundation | |
| struct DateUtil { | |
| static func getModifiedDate(date: Date, currentDate: Date) -> 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
| enum SFSymbols { | |
| static let location = UIImage(systemName: "mappin.and.ellipse") | |
| static let repos = UIImage(systemName: "folder") | |
| static let gists = UIImage(systemName: "text.alignleft") | |
| static let followers = UIImage(systemName: "heart") | |
| static let following = UIImage(systemName: "person.2") | |
| } |
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
| enum SocialMediaPlatofrm { | |
| case twitter(followers: Int) | |
| case youtube(subscribers: Int) | |
| case instagram | |
| case linkedin | |
| } | |
| func getSponshorshipEligibility(for platofrm: SocialMediaPlatform) { | |
| switch platform { | |
| case .twitter(let followers) where followers > 10_000: |
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 ConfirmationTextField: View { | |
| @State private var showtextFieldToolbar = false | |
| let keyboardType: UIKeyboardType | |
| @Binding var text: String | |
| var body: some View { | |
| TextField("", text: $text) | |
| { isChanged in | |
| if isChanged { | |
| showtextFieldToolbar = true |
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
| // Filter array to only the drinks in the last 24 hours. | |
| private func filterDrinks(drinks: [Drink]) -> [Drink] { | |
| // The current date and time. | |
| let endDate = Date() | |
| // The date and time 24 hours ago. | |
| let startDate = endDate.addingTimeInterval(-24.0 * 60.0 * 60.0) | |
| // return an array of drinks with a date parameter between | |
| // the start and end dates. |
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
| /* | |
| See LICENSE folder for this sample’s licensing information. | |
| Abstract: | |
| A data controller that manages reading and writing data from the HealthKit store. | |
| */ | |
| import Foundation | |
| import HealthKit |
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
| // Returns the URL for the plist file that stores the drink data. | |
| private func getDataURL() throws -> URL { | |
| // Get the URL for the app's document directory. | |
| let fileManager = FileManager.default | |
| let documentDirectory = try fileManager.url(for: .documentDirectory, | |
| in: .userDomainMask, | |
| appropriateFor: nil, | |
| create: false) | |
| // Append the file name to the directory. |
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
| // A background queue used to save and load the model data. | |
| private var background = DispatchQueue(label: "Background Queue", | |
| qos: .userInitiated) | |
| // Save the data on a background queue. | |
| background.async { [unowned self] in | |
| do { | |
| try data.write(to: self.getDataURL(), options: [.atomic]) |
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
| // The list of drinks consumed. | |
| // Because this is @Published property, | |
| // Combine notifies any observers when a change occurs. | |
| @Published public var currentDrinks = [Drink]() | |
| // A sink that is also called whenever the currentDrinks array changes. | |
| var updateSink: AnyCancellable! | |
| // Add a subscriber to currentDrinks that responds whenever currentDrinks changes. |