Post

Replies

Boosts

Views

Activity

Swift UI Preview for Multiple Entity
Hello, I've created multiple Entity in CoreData, that has a relationship to one another. However, I'm unable to create @discardableResult to use in SwiftUI preview. /// Entity data for use with canvas previews. static var preview: Entity1 {         let entities1 = Entity1.makePreviews(count: 1)         return entities1[0] } @discardableResult static func makePreviews(count: Int) -> [Entity1] {         var contents = [Entity1]()         let viewContext = PersistenceController.preview.container.viewContext         let persistenceController = PersistenceController.shared         for index in 0..<count {             let entities1 = Entity1(context: viewContext)             entities1.id = UUID()             entities1.title = "Amazing day!"             let photo = Photo(context: viewContext)             let imageData = UIImage(named: "Golden Temple")?.jpegData(compressionQuality: 1) ?? Data()             photo.linkedToJournal = journal             let thumbnail = Thumbnail(context: viewContext)             let thumbnailData = persistenceController.thumbnail(with: imageData)?.jpegData(compressionQuality: 1)             thumbnail.data = thumbnailData             thumbnail.photo = photo             let photoDataObject = PhotoData(context: viewContext)             photoDataObject.data = imageData             photoDataObject.photo = photo             contents.append(entities1)         }         return contents } You may also try to use the sample code from https://developer.apple.com/documentation/coredata/sharing_core_data_objects_between_icloud_users to build a SwiftUI Preview. Appreciate if you could suggest how to build a SwiftUI preview as it saves a lot of development effort and time. Thank you very much!
1
0
1.2k
Dec ’22
How to Fetch SunEvents?
Hello, I'm quite new to SwiftUI Development, learned how to code without getting a Compute Science college Degree. Please advise how do I fetch SunEvents? private func showWeatherInformation(latitude: Double, longtitude: Double) async {         let weatherService = WeatherService()         let journalingWeather = CLLocation(latitude: latitude, longitude: longtitude)                  do {             let weather = try await weatherService.weather(for: journalingWeather)             let temperature = weather.currentWeather.temperature.value.description             let humidity = weather.currentWeather.humidity.formatted(.percent).description             let weatherDesc = weather.currentWeather.condition.description             let weatherIcon = weather.currentWeather.symbolName.description             let feltLikeTemp = weather.currentWeather.apparentTemperature.value.description             let pressure = weather.currentWeather.pressure.value.description             let dewPoint = weather.currentWeather.dewPoint.value.description             let uvIndex = weather.currentWeather.uvIndex.value.description             let visibility = round(weather.currentWeather.visibility.value).description             let windSpeed = weather.currentWeather.wind.speed.value.description             let compass = weather.currentWeather.wind.direction.value.description                          /// What to decode?             let sunEvents = try SunEvents(from: journalingWeather as! Decoder)             let sunrise = sunEvents.sunrise ?? Date.now             let sunset = sunEvents.sunset ?? Date.now                          self.temperatureInput = temperature             self.weatherDescriptionInput = weatherDesc             self.weatherIconInput = weatherIcon             self.feltLikeTemperatureInput = feltLikeTemp             self.pressureInput = pressure             self.humidityInput = humidity             self.dewPointInput = dewPoint             self.uvIndexInput = uvIndex             self.visibilityInput = visibility             self.windSpeedInput = windSpeed             self.windDegreeInput = compass             self.sunriseTimeInput = sunrise             self.sunsetTimeInput = sunset         } catch {             print("\(error)")         }     } I'm getting this error Thread 1: signal SIGABRT at let sunEvents = try SunEvents(from: journalingWeather as! Decoder) when I run it on actual device. Any help would be very much appreciated. Thank you!
3
0
1.8k
Aug ’22
Unable to Save Intents
Hi All, I'm using Core Data to store my data. I've followed the guide in the video but unable to complete the final steps. /// The core data stack `Data`     var dataProvider: datasProvider = .shared          func handle(intent: CreateNoteIntent, completion: @escaping (CreateNoteIntentResponse) -> Void) {         let title = intent.title!         let isBookmark = intent.isBookmark!         let photo = UIImage()                  let newIntent = Task { await self.dataProvider.addData(time: Date(), title: title, isFavorite: isBookmark as! Bool, image: photo) }                  let response = CreateNoteIntentResponse(code: .success, userActivity: nil)         response.noteIntent = newIntent //Error: Cannot assign value of type 'Task<(), Never>' to type 'Type'         completion(response)     } I'm using SwiftUI and it is for iOS app. Does anyone have a solution for this or can explain to me what went wrong please. Spent few hours figuring this out. Any help will be appreciated. Thank you.
2
0
904
Oct ’21
On Continue User Activity with Swift UI
Hi All, I'm very new to iOS development and Swift UI is my first coding language. I'm trying to link the users search results in Spotlight with the detail view that is stored in Core Data. I can search for users data in spotlight but when I tap on it, it's only appearing in the main view of the app. Is there anyways that I can use .onContinueUserActivity at the launch of the app or is there any different code that I have to use? I've searched for many articles but I couldn't get a solution. It would be good if anyone can share some links or guide here. Thank you. .onContinueUserActivity(DetailView.productUserActivityType) { userActivity in             if let product = try? userActivity.typedPayload(Product.self) {                 selectedProduct = product.id.uuidString             }         } I get this code from Apple's State restoration app but I can't use this with Core Data.
1
0
1.3k
Aug ’21
CoreData
Hi All, I'm very new to iOS app development. I've managed to complete the Scrumdinger tutorial. However, I would like to know how can I use CoreData or CloudKit to persist the data. URL: https://developer.apple.com/tutorials/app-dev-training/persisting-data I'm having trouble to bind the data to EditView(). Is there any online guide or tutorial that can help me? Thank you!
2
0
1.4k
Jun ’21