Post

Replies

Boosts

Views

Activity

Reply to WeatherKit or SwiftUI date formatting issues
Get the time zone of the location and use that: import Foundation let sanFrancisco = TimeZone(identifier: "PST") let time = Date.now let timeFormatter = DateFormatter() timeFormatter.dateStyle = .none timeFormatter.timeStyle = .short timeFormatter.timeZone = sanFrancisco timeFormatter.locale = .current let timeStr = timeFormatter.string(from: time) print("\(timeStr)") // For me, prints 2.08, local time was 12.08. And, if starting from a coordinate, rather than a timezone identifier: import Foundation import CoreLocation let sanFrancisco = CLLocation(latitude: 37.77493, longitude: -122.41942) let geoCoder = CLGeocoder() do { let placemarks = try await geoCoder.reverseGeocodeLocation(sanFrancisco) if !placemarks.isEmpty { if let placemark = placemarks.first { let time = Date.now let timeFormatter = DateFormatter() timeFormatter.dateStyle = .none timeFormatter.timeStyle = .short timeFormatter.timeZone = placemark.timeZone timeFormatter.locale = .current let timeStr = timeFormatter.string(from: time) print("\(timeStr)") } else { print("No placemark for the coordinate") } } } catch { print("Failed to geolocate coordinate: \(error.localizedDescription)") }
Jun ’23
Reply to Coding help requested
You specify the sound to play: let chimesSoundEffect = "Chimes-sound-effect.mp3" But then use a different one when loading the sound file: guard let url = Bundle.main.url(forResource: "sound", withExtension: "mp3") else { return } Should you use the one you specify in the variable (without the extensions since you provide it as withExtension parameter): let chimesSoundEffect = "Chimes-sound-effect" ... guard let url = Bundle.main.url(forResource: chimesSoundEffect, withExtension: "mp3") else { return } Hard to say otherwise what could be the issue. If you'd like someone else to test and help out getting this to work, I'd say put this in GitHub as a public repository and let others contribute there. It would be lots of work for others to create an empty project to test out this code of yours there, including putting mp3 files in resources of the app. And if the issue is elsewhere in your project (like where the mp3 file is located), seeing this code only may not be enough to solve your issues.
Jun ’23
Reply to WARNING: Application performed a reentrant operation in its NSTableView delegate. This warning will become an assert in the future.
Having the same problem, anyone has anything new to help solve the issue? I have a NavigationSplitView with three columns and a .searchable()on the first column List view. Data to the views come from Core Data @FetchRequest. Whenever user removes a character from the search field or clears the search field, the same warning is displayed. When entering search text, warning does not appear. This does not happen always. For example when I enter a search text resulting in one row, and then remove one letter from search text. Then three rows are displayed and this warning does not appear. After removing another letter, resulting to five rows appearing, then this warning appears. Relevant parts of code below. struct ContentView: View { @Environment(\.managedObjectContext) var moc @FetchRequest (sortDescriptors: [SortDescriptor(\.subject)]) private var categories: FetchedResults<Category> @State private var selectedCategory : Category? = nil @State private var selectedTerm: Term? = nil @State private var searchText = "" var body: some View { NavigationSplitView { List(selection: $selectedCategory) { ForEach(categories, id: \.self) { category in CategoryRowView(category: category) .swipeActions(edge: .trailing) { Button(role: .destructive) { toDeleteCategory = category showDeleteCategoryConfirmation.toggle() } label: { Label("Delete", systemImage: "trash") } } } } .listStyle(.sidebar) .searchable(text: $searchText) ... } content: { if let category = selectedCategory { List(category.viewTerms(filter: searchText.isEmpty ? nil : searchText), id: \.self, selection: $selectedTerm) { term in and the implementation of category.viewTerms(filter: ) that does the filtering based on searchText (Category is a Core Data class): extension Category { ... func viewTerms(filter: String?) -> [Term] { var terms = viewTerms if filter != nil { terms = terms.filter( { $0.termSearchText.localizedCaseInsensitiveContains(filter!) } ) } return terms } var viewTerms: [Term] { let terms = categoryTerms?.allObjects as? [Term] ?? [] return terms.sorted(by: {$0.viewPrimaryName < $1.viewPrimaryName } ) } Where the Category.categoryTerms is a one-to-many Core Data relationship from Category entity to Term entity.
Jun ’23
Reply to Xcode X Switt X SQLite
Should this...: fmResultSet = ... ...be: let fmResultSet = ... ..instead? And apparently: while fmResultSet!.next() == true Is not the valid way since next() returns the next result object, not a boolean value true or false. So perhaps you need to replace that with: while fmResultSet!.next() != nil Later you use the isEmpty property, and that is either true or false but you compare that to nil instead.
May ’23
Reply to Newbie help pls
If he sent the code, those are just text files and you can view them with any text editor. Unless he used Interface Builder, in that case it would be a bit inconvenient to view the GUI files. If you wish to test the app, why doesn't the developer send you the app he build that runs on your environment?
May ’23
Reply to Outlook for Mac Disaster
If you complain about how Outlook works, you should go complain in Microsoft forums since they develop it. Not Apple. If you complain about Apple developed software from the user perspective, then you should go complaining to user support forums, not developer forums.
May ’23
Reply to Help, I need to save an object in CoreData
If you need several data items in a database table (as array in your case), the usual solution is to have two tables with a one-to-many relation to the other table having the multiple values. In Xcode core data modelling terms, you'd have two entities and a one-to-many relationship between them. Alternatively, you could do this in code, storing e.g. a comma separated string of elements in a string attribute. But then you'd have to implement parsing and generating this string yourself in code.
May ’23