1.What is the best way to link/store each User's info to a Post using CloudKit with CoreData?
How can I make it that whenever the user changes their photo and I update the UserInfo record, have all the POST made by this user have the new updated photo?
.xcdataModel file has a Post entity
Post with the following attributes:
caption: String, image: binary Data, postID: String, postText: String, userID: String, username: String
I use the managedobjectContext method in SwiftUI to add Posts to the database like below.
post.username = cloudkitManager.currentUser?.name
post.userID = cloudkitManager.userDefaultsID
post.postText = self.viewModel.serialNumber
post.postID = UUID().uuidString
post.timestamp = Date()
if self.viewModel.imageData() != nil {
post.image = self.viewModel.imageData()
}
do {
if viewContext.hasChanges {
try viewContext.save()
self.viewModel.isLoading = false
self.presentationMode.wrappedValue.dismiss()
}
} catch {
self.viewModel.isLoading = false
let nsError = error as NSError
self.viewModel.errorMessage = error.localizedDescription
self.viewModel.showErrorAlert = true
fatalError("Unresolved error \(nsError), \(nsError.userInfo)")
}
But when saving the UserInfo I use a normal CloudKit container.publicCloudDatabase.save method instead of using the managedObjectContext like above
Any Advise please help :)
Post
Replies
Boosts
Views
Activity
how can I use CloudKit to make a chat messaging section in my app. I want users to be able to have private conversations with another user without it being public to everyone.
I don’t want to use public database cause then everyone would see the 2 users personal convo.
I don’t want to use private database because I want both users to be able to see the messages sent to each other in convo.
I normally would use Firebase with messagekit for this but I want to try with CloudKit .
any help would be appreciated
I am using CoreData with CloudKit but I notice that all my posts are only being saved in the Private database of CloudKit
how can I get them to save in the Public database of CloudKit instead while using CoreData and CloudKit?
I am using CoreData with CloudKit in SwiftUI and am able to save data but its only saving to the Private Database, how can i chose to save some data in different database example: Public Database instead of the Private Database.
Also what is the Shared Database for exactly? (is it for messages between two users in a chat style)
Recently iOS 14 added auto scrolling to textfields, or other in focus views in a ScrollView.
How can i disable the recently added Autoscrolling in iOS 14 for SwiftUI
i have a Custom button in SWIFTUI but when I run the accessibility inspector and it focuses on button it only says the title and type.
how can I get it to say whether it is enabled or not
When there is a toggleStyle added to my Toggle, the Toggle's TapGesture stops responding unless i remove the toggleStyle. However the Text inside the Toggle's closure Text("Some Text")
still responds to tap but not the tapgesture on the Toggle itself with the print("Toggle Tapped")
Toggle(isOn: $shouldToggle) {
Text("Some Text")
			.onTapGesture {
				 print("Some Text Tapped")
				 }
}
		.onTapGesture {
				 print("Toggle Tapped")
				 }
		.toggleStyle(MyCustomToggleStyle())
How can i use a dictionary of type [SomeObject : [ValueObjects]]that belongs to viewModel(ObservableObject) to make a SwiftUI List using ForEach?
I want to align a small image right next to multiline text at THE LAST WORD for the text in a HStack like below:
var body: some View {
HStack(alignment: .lastTextBaseline, spacing: 0) {
Text("Long Multine Line Text in List.adhjshdsjhdshdjshdjsbdjbdsajdbjbdajbdsajdbjasbdjadbajbdjabdjadbjadbjasdddfds")
Image(systemName: "pencil")
}
}
}
But when i do this the Image is at the same level of the last line in multine line text BUT there is spacing between them as if the image is outside of the Text's frame(not sure),
How can i have the image right next to the Multiline Text?
i am using NsPersistentCloudkitContainer with CoreData and CloudKit to manage my database.
When I save data to the managedObjectContext I see my data model ‘Post’ added in Schema as a Record Type in the CloudKit Dashboard , but when I go to the Data section I still don’t see any data added.
can anyone help why this is happening?
I have a Post Model type that i made in .xcdatamodel, then switched Codegen to Manual/None and got two files Post+CoreDataClass & Post+CoreDataProperties
In my AddPostView I am saving changes like below:
post.title = self.viewModel.postTitle
post.comment = self.viewModel.postComment
post.serialNumber = self.viewModel.postSerialNumber
do {
if self.managedObjectContext.hasChanges {
try self.managedObjectContext.save()
}
self.isShown.toggle()
} catch {
self.showErrorAlert.toggle()
print(error.localizedDescription)
}
When this executes i see the record type in CloudKit Dashboard Schema, Record Type but when i go to the Data section I dont see any data added.
Anyone can help why this may. be happening?
I am adding some data in CloudKit with my record type called Post made in my .xcdatamodeld but all of my entry field names are adding the "CD_"
below is the logic im using :
add the environmentObject at the top of the view
@Environment(\.managedObjectContext) var managedObjectContext
saving to cloudkit using manageobjectcontext
var post = Post(context: self.managedObjectContext)
post.title = self.viewModel.addPostTitle
post.comment = self.viewModel.aboutPostComment
post.serialNumber = 23
do {
try self.managedObjectContext.save()
} catch {
print(error)
}
my records should be returning example: "comment" but is instead returning "CD_comment"
my iMAC 2017 keeps crashing and shuts down if i leave it and it goes to sleep.
I then have to hold down the power button multiple times for it to turn back on. This all started happening after i updated my OS to the latest release few days ago.
Can anyone help with this?
I am trying to add an image to the right of text to make the image appear inline.
However when i do this with a HStack the image is to the right of the image for 1 line text but multi line text the image is just to the right of the frame of the view for the text and not Inline as i need eg.
HStack {
Text("Some Long Text")
Image("info.circle")
}