I'm making an Apple Watch app and an iPhone app.
The structure of the app is as follows.
(On Apple Watch) Count the number and store it in Userdefault.(title, number)
(On Apple Watch) Press the 'Count Complete' button to send the title and number data to the iPhone app.
(In the iPhone app) Save the data received from the Apple Watch as CoreData.
Here's the problem.
I don't know the proper way to transfer the data (title, number) generated by the Apple Watch to the iPhone.
Post
Replies
Boosts
Views
Activity
I have a problem with CoreData.
Is there any way to directly save the data received by WCSession didreceiveuserinfo to CoreData?
I want to save the data in Core Data as an array and express it as a chart.
Can data in Core Data be combined by date and expressed in a chart?
I want to store the last 7 data of Core Data in an array.
The structure of the entity is as follows.
date, title, goal, nogoal, id.
I want to store the last 7 goal records in an array.
If there is an angel who can do it, please help me.
Can't i just store specific attributes of an entity as an array?
Entity :
goals
attributes :
date(date),
title(String),
goal(Int16),
failgoal(Int16),
id(UUID)
I am studying using core data. Especially the fetchrequest is difficult.
Can't i save the last 7 values of a specific attribute of coredata in an array?
The goal is to use the charts package. I want to call 7 attribute values and express them in a chart.
I want to get data from coredata and present it as a chart.
During the build process, it builds without any problem, but the chart is not visible when the actual app is run.
I put some data in coredata.
Why?
import SwiftUI
import SwiftUICharts
import CoreData
struct ChartView: View{
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest var items: FetchedResults<Item>
@State var demoData: [Double] = []
init() {
let request: NSFetchRequest<Item> = Item.fetchRequest()
request.sortDescriptors = [
NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)
]
request.fetchLimit = 7
_items = FetchRequest(fetchRequest: request)
for i in items{
demoData.append(i.think)
}
}
var body: some View{
BarChart()
.data(demoData)
.chartStyle(ChartStyle(backgroundColor: .white,
foregroundColor: ColorGradient(.blue, .purple)))
}
}
I want to plot the data stored in coredata as a chart. (using SwiftUI)
The entity structure of the project is as follows.
entity name: Item
attribute : name(String), success(Int), date(Date)
Among the above attributes, I want to draw the trend of the success attribute as a bar chart.
I did find a suitable package for drawing charts. It is 'Charts' by appear.
To draw a chart, you need to put success data in the data array, which is difficult.
Either way it doesn't matter. Please suggest a specific way to draw a chart.
For reference, I am attaching the code I used.
import SwiftUI
import SwiftUICharts
import CoreData
struct ChartView: View{
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest var items: FetchedResults<Item>
var demoData: [Double] = []
@State var thinkData = []
init() {
let request: NSFetchRequest<Item> = Item.fetchRequest()
request.sortDescriptors = [
NSSortDescriptor(keyPath: \Item.date, ascending: true)
]
request.fetchLimit = 7
_items = FetchRequest(fetchRequest: request)
for i in items{
demoData.append(Double(i.success))
}
}
var body: some View{
HStack{
Spacer()
BarChart()
.data(aData)
.chartStyle(ChartStyle(backgroundColor: .white,
foregroundColor: ColorGradient(.blue, .purple)))
Spacer()
}
}
}
Open the detail view with navigationlink.
How to edit data in detail view?
Is there a way to automatically save when I edit text in textfield like note app?
I use coredata.
I am using coredata.
Draw a rectangle by taking only 2 values with ForEach.
However, when I add new data or modify the data, the app crashes.
ForEach must have a maximum index value of 1. This is because the limit of fetchrequest is 2. However, when I add new data, the value of index becomes 2 and get an 'out of range' error.
I've been looking for an answer for 16 hours.
import SwiftUI
struct chart: View{
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest var datas: FetchedResults<Mind>
@State var show = [true, false]
init() {
let request: NSFetchRequest<Success> = Mind.fetchRequest()
request.sortDescriptors = [
NSSortDescriptor(keyPath: \Success.date, ascending: false)
]
request.fetchLimit = 2
_datas = FetchRequest(fetchRequest: request)
}
var body: some View{
VStack(alignment: .leading){
ForEach(0..<datas.map{$0.suc}.count, id: \.self){ index in
RoundedRectangle(cornerRadius: 5)
.fill(Color.objcolor.opacity(show[index] ? 1 : 0.7))
.frame(width: 10, height: 5)
}
}
}
}
overview of the problem
I'm making an app with SwiftUI.
We even implemented fetching contacts using CNContactStore.
The goal is to get the contacts and store them separately in CoreData.
This is because you need to assign and manage attributes that are not in the default contact.
class ContactStore: ObservableObject {
@Environment(\.managedObjectContext) private var viewContext
@Published var error: Error? = nil
@Published var results: [CNContact] = []
func fetch() {
do {
let store = CNContactStore()
let keysToFetch = [CNContactGivenNameKey as CNKeyDescriptor,
CNContactMiddleNameKey as CNKeyDescriptor,
CNContactFamilyNameKey as CNKeyDescriptor,
CNContactImageDataAvailableKey as CNKeyDescriptor,
CNContactPhoneNumbersKey as CNKeyDescriptor,
CNContactImageDataKey as CNKeyDescriptor]
os_log("Fetching contacts: now")
let containerId = store.defaultContainerIdentifier()
let predicate = CNContact.predicateForContactsInContainer(withIdentifier: containerId)
let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch)
os_log("Fetching contacts: succesfull with count = %d", contacts.count)
self.results = contacts
print(results)
} catch let error {
print("error occured! : \(error.localizedDescription)")
}
}
}
problem
Is there a way to store the contact information in the array 'results' as CoreData?
The attributes set in CoreData are 'name', 'phone', and 'company'.
Is there a way to optimize a List in SwiftUI?
There is a problem with selection not working properly when the List has many rows.
If you scroll to multi-select and up, some rows in the middle are not selected.
I have an issue where selecting an unselected row deselects nearby rows.
Is there any way for selection to work reliably even for a List of many rows?
I would like to find a solution that is stable even when multiple lines are selected, like mail and note, which are the default apps in ios.
ps. I am using CoreData.
@State var selectedItem = Set<MyEntity>()
List(selection: $selectItem){
ForEach(items, id: \.self){ item in
ContactsRow(contactsData: item)
}
}
.environment(\.editMode, $editMode)
I used List(select:) to make it selectable. When scrolling to select many rows, the selected content sometimes disappears. Is running out of memory a problem? While the default app in ios has smooth multi-selection, it is unstable when using swiftui's list function.
Multi-select in the mail app, for example, doesn't run out of memory when many rows are selected. How do you achieve this perfection?
The code is nothing special. Create a list with List(select:) and rows with ForEach(array, id:.self).
I'll attach a video
https://i.stack.imgur.com/2px9i.gif
hello. I am a beginner developer.
I am creating a camera app using swiftui.
I want to create an app that allows you to take pictures with a camera, apply filters, and save them.
I'm practicing following Apple's sample tutorial.
https://developer.apple.com/tutorials/sample-apps/capturingphotos-camerapreview
It was possible to apply CIFilter to the image displayed in the viewfinder, but I don't know how to apply the filter to the saved photo.
I'd like to get some hints on this.
Hello,
I am a developer currently working on a personal contact management app.
What is the app?
My app stores additional information beyond basic contact details. Therefore, instead of using the Contacts framework, I manage contact objects using Core Data.
What am I trying to achieve?
I want to display additional information on the caller ID screen when a call is received from a number stored in my app.
What have I tried?
I’ve attempted the following methods without success:
1. Call Directory Extension:
I thought using this method would allow me to display additional information from Core Data on the call screen. However, I learned that when a call is received, the iOS system first searches for the phone number in the Contacts app and only looks to the Extension app if no match is found. Therefore, displaying contact information from my app seems unfeasible.
2. Custom Call UI:
Using CallKit seemed like a viable option to display the necessary information during a call, but it appears to only be possible with VoIP apps. My app does not support VoIP calls, so this method was also not implementable.
I am wondering if there are any technologies available that could help me achieve my goal, or if there’s something I might be missing. Any advice would be greatly appreciated.
Thank you!
If a similar question has been asked, I apologize for the repetition.