Post

Replies

Boosts

Views

Activity

Reply to What would be the best logic for updating a file periodically after an app has been released
Thanks a lot for the good ideas. The one thing I don't think I was clear on, was the fact that the update will always be triggered manually and will be followed by a new AppStore submission. I'll basically decide in what app version/release I want to run the update. In other words, the update could happen sooner than a year. What I was thinking is something like my first example but with the ability to be able to manually forece-change the shouldLoad variable to true for all users, existing and new at any point. Again, the update would need to happen to all users, and new users do not need to know about the original content in the file as long as the latest is loaded.
Jan ’23
Reply to Throwing paper/ball animation effect in SwiftUI
I gave up after spending a lot of time trying to do the animation in SwfitUI and ended up reusing the existing UIKit animation using a UIViewRepresentable as suggested in the following thread. http://stackoverflow.com/questions/70553786/animating-a-swiftui-view-with-uiview-animate/70645853#70645853/ import SwiftUI struct WrapUIKitAnimationInSwiftUI: View { @State private var isAnimating = false var body: some View { HStack{ Image(systemName: "circle.fill") .font(.system(size: 65)) .foregroundColor(.blue) .throwAnimation(isAnimating: $isAnimating) .onTapGesture { isAnimating.toggle() } } } } struct ThrowAnimationWrapper<Content: View>: UIViewRepresentable{ @ViewBuilder let content: () -> Content @Binding var isAnimating: Bool func makeUIView(context: Context) -> UIView { UIHostingController(rootView: content()).view } func updateUIView(_ uiView: UIView, context: Context) { if isAnimating{ UIView.animateKeyframes(withDuration: 1.5, delay: 0.0, options: [.calculationModeCubic], animations: { UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.2, animations: { uiView.center = CGPoint(x: 250, y: 300) }) UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.9, animations: { uiView.center = CGPoint(x: 100 + 75, y: 100 - 50 ) uiView.transform = CGAffineTransform(scaleX: 0.75, y: 0.75) }) UIView.addKeyframe(withRelativeStartTime: 0.1, relativeDuration: 0.7, animations: { uiView.center = CGPoint(x: 100, y: 100) uiView.transform = CGAffineTransform(scaleX: 0.2, y: 0.2) }) }, completion: { _ in uiView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0) }) } } } extension View { func throwAnimation( isAnimating: Binding<Bool>) -> some View { modifier(ThrowAnimationViewModifier(isAnimating: isAnimating)) } } struct ThrowAnimationViewModifier: ViewModifier { @Binding var isAnimating: Bool func body(content: Content) -> some View { ThrowAnimationWrapper(content: { content }, isAnimating: $isAnimating) } }
Sep ’22
Reply to How to update the CloudKit schema after the app has been released to the AppStore
CloudKit Limitations: Mirroring a Core Data Store with CloudKit | Apple Developer Documentation Determine If Your App Is Eligible for Core Data with CloudKit Apps adopting Core Data can use Core Data with CloudKit as long as the persistent store is an NSSQLiteStoreType store, and the data model is compatible with CloudKit limitations. For example, CloudKit does not support unique constraints, undefined attributes, or required relationships.
Jun ’22
Reply to How to turn On/Off iCloudKitSync on a SwiftUI application
Not really a lot of data, about 10-50 objects with 10 properties each. So you think the most appropriate thing to do is use the local container if sync is off and switch to cloudKit container if it's on? My main struggle is not knowing how to structure my code in a way that I can turn On/Off sync on runtime from other views to test it and see if it will work.
Jan ’22
Reply to Understanding CloudKit Communication
Here is the code I'm using... Connection to the Private Database let privateDatabase = CKContainer.default().database(with: .private) Reading records `privateDatabase.perform(query, inZoneWith:nil){( results , error) in ... } Writing Records privateDatabase.save(ckRecord){ (record, error) in ...} What I ultimately need to know is whether I need to check if the user is logged in or not when accessing the database to avoid redundant code/checks. Thanks
Jun ’20
Reply to New CKRecord in custom zone
Here is the code to save a record in a custom zone.func addRecordToCustomZone() { let ckRecordZoneID = CKRecordZone(zoneName: "CustomZoneName") let ckRecordID = CKRecord.ID(zoneID: ckRecordZoneID.zoneID) let aRecord = CKRecord(recordType: "Cars", recordID: ckRecordID)// Cars is the data Type aRecord["carMake"] = "Porche" // carMake is a field in the Cars Type. aRecord["carModel"] = "Carrera" // carModel is a field in the Cars Type. privateDatabase.save(aRecord, completionHandler: { (record, error) -&gt; Void in if let error = error { print(error) } else { print("record saved successfully") } }) }Please note that you also have the option of adding your own record name if you like by specifying it in the `CKRecord.ID` as follow.let ckRecordID = CKRecord.ID(recordName: "SomeUniqueName", zoneID: ckRecordZoneID.zoneID)
May ’20
Reply to What is the proper way to read shared items from the Shared Database in CloudKit
Apparently the name of your `CustomZone` record changes when it gets added to the Shared Database so, you first need to retrieve all custom zones from the shared database.I found the answer thanks to the following two threads.https://stackoverflow.com/questions/40603657/cloudkit-sharinghttps://stackoverflow.com/questions/56163096/unable-to-fetch-records-in-a-sharedclouddatabase-custom-zone-using-cloudkit##CODE: @IBAction func readSharedRecords(_ sender: Any) { let sharedData = CKContainer.default().sharedCloudDatabase sharedData.fetchAllRecordZones { (recordZone, error) in if error != nil { print(error?.localizedDescription ?? "Error") } if let recordZones = recordZone { for i in 0..&lt;recordzones.count{ // find the zone you want to query if recordZones[i].zoneID.zoneName == "ListsZone"{ self.sharedRecords(zID: recordZones[i].zoneID) } } } } } func sharedRecords(zID: CKRecordZone.ID){ let privateDatabase = CKContainer.init(identifier: "iCloud.com.mySite.lists").database(with: .shared) let predicate = NSPredicate(value: true) let query = CKQuery(recordType: "Items", predicate: predicate) privateDatabase.perform(query, inZoneWith: zID){( results , error) in guard error == nil else{ print("Error: \(String(describing: error?.localizedDescription))") return } if let itemsFromResults = results{ print("Items: \(itemsFromResults)") } } }
May ’20
Reply to Why do I get an error when deleting data from SwiftUI List and Realm?
Yes, line 46 executes the deleteRow() method. try! realm.write is the Realm syntax to be able to perform changes to the database. I'm deleting results[0] when a button is tapped just to test and make sure it wasn't the swipe delete causing the error. Deleting results[0] should indeed remove the first item and refresh the List but it's not doing it, that's mainly my issue. It does work when adding new items to Realm.For instance, if I add a new dog object the List immediately updates. try! realm.write{ realm.add(dog) }The error points to the appDelegate.swift file (Thread 1: signal SIGABRT).Thanks!
Apr ’20