Hello,
I noticed there's a glitch with inspect element. Under elements, when I try to uncheck a style property, the whole element's CSS gets removed, sometime's the whole webpage's. I was wondering if there was anything I could do to fix this issue.
Thanks
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,
I have a button view that is used in many different ways in an app that I'm working on. One of the ways it is used is in an account creation form. Since the button is in a child view, the action: { } button function isn't available in the view where the input field variables are. I could import the class with the function to the button view but I don't want to pass the input field variables into the button view. I tried binding a boolean variable to the button view and checked for it's state change in the parent view using .onChange(), but the use case for that I found was depreciated and I'm unable to revert the state of the variable in the .onChange function.
To reiterate, in a main view, I need to call a function in a given class and pass variables to it, upon a button being pressed in a child view. Any help would be greatly appreciated.
Hi,
If I were to make version 2 of my Xcode Project, would I be able to create a new revision within the project itself, or would I need to make an entirely new project?
Any guidance would be greatly appreciated. Thank you.
Hi,
When using just one model container, I have the following code:
let modelContainer: ModelContainer
init() {
do {
entriesModel = try ModelContainer(for: Model.self)
} catch {
fatalError("Could not initialize ModelContainer")
}
}
I am attempting to implement two like so:
let model1: ModelContainer
let model2: ModelContainer
init() {
do {
model1 = try ModelContainer(for: Model1.self)
model2 = try ModelContainer(for: Model2.self)
} catch {
fatalError("Could not initialize ModelContainer")
}
}
var body: some Scene {
WindowGroup {
ContentView()
.modelContainer(model1)
.modelContainer(model2)
}
}
However, when in the Views that I'd like to implement I don't know how to declare the models. I tried this:
@Environment(\.model1) private var model1
@Query private var data: [Model1]
But I get the error: Cannot infer key path type from context; consider explicitly specifying a root type
How do I implement multiple model containers in multiple different views?
I have a @Model class that is comprised of a String and a custom Enum. It was working until I added raw String values for the enum cases, and afterwards this error and code displays when opening a view that uses the class:
{
@storageRestrictions(accesses: _$backingData, initializes: _type)
init(initialValue) {
_$backingData.setValue(forKey: \.type, to: initialValue)
_type = _SwiftDataNoType()
}
get {
_$observationRegistrar.access(self, keyPath: \.type)
return self.getValue(forKey: \.type)
}
set {
_$observationRegistrar.withMutation(of: self, keyPath: \.type) {
self.setValue(forKey: \.type, to: newValue)
}
}
}
Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1cc165d0c)
I removed the String raw values but the error persists. Any guidance would be greatly appreciated. Below is replicated code:
@Model
class CopingSkillEntry {
var stringText: String
var case: CaseType
init(stringText: String, case: CaseType) {
self.stringText = stringText
self.case = case
}
}
enum CaseType: Codable, Hashable {
case case1
case case1
case case3
}
Hi,
I have two SwiftData models that are not working as intended. I'm able to add data to the models, but sometimes after refreshing the app data is missing. Any guidance would be greatly appreciated.
Hello,
I'm using PaintCode for UIGraphics which exports Swift files with an @objc dynamic public class func nested in a NSObject class. With older versions of Swift, could be implemented with the use of a UIKit view and the storyboard.
How could I do this with SwiftUI?
Thanks in advance.
Hello,
I'm having trouble previewing a view that has a binding variable. When it's in the below state, I get the error "Edit placeholder in source file":
static var previews: some View {
Navigation(viewState: Binding<String>)
}
}
When I put a string as a placeholder, I get the error: Cannot convert value of type 'String' to expected argument type 'Binding'
static var previews: some View {
Navigation(viewState: "sign-in")
}
}
The code for the supporting view with the binding variable is below:
struct Navigation: View {
@Binding var viewState: String
var body: some View {
ZStack {
HStack {
Spacer()
Button(action: { toggleView(view: "savings")}) {
Text("Savings")
}
Spacer()
Button(action: { toggleView(view: "settings")}) {
Text("Settings")
}
Spacer()
}
}
.position(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height / 2)
.frame(width: UIScreen.main.bounds.width, height: 100)
}
func toggleView(view: String) {
viewState = view
}
}
Any help would be greatly appreciated.
Hi,
I am inquiring in regard to how to handle data from a bluetooth device. The device would send data in JSON format to a Mac via bluetooth, and I would need to constantly refresh or fetch data from the device in real time.
How would I go about this? Any help would be greatly appreciated.
Thank you.
Topic:
Programming Languages
SubTopic:
Swift
Tags:
External Accessory
IOBluetooth
Swift
Core Bluetooth
Hello,
I'm inquiring in regard to information on handling user's subscriptions, specifically if it's possible to cancel a subscription with a line of code. For example:
if condition {
// cancel user's subscription
}
I'm not familiar with the App Store Server API yet, but I glanced at the documentation and I didn't see any information in regard to the question I have. That being said, I'm also wondering where to start with configuring a subscription model for my app.
Any insights would be greatly appreciated. Thank you.
Hi,
I'm inquiring in regards to the feasibility or possibility of making a connection from iPhone to another, such that one iPhone uses Apple wallet, and another iPhone would detect for the signal within the app. Please let me know if this is feasible or if any more information would be necessary to assist. If this is possible, what documentation would be relevant?
Thank you.
Hi,
I was searching and replacing code where all of the sudden I got the following errors:
Undefined symbol: AppName.Client.init(id: Swift.Int, name: Swift.String, StructVariable: Swift.Int?, structVariable: [Struct]?) -> AppNameStruct
Linker command failed with exit code 1 (use -v to see invocation)
I replaced the names in the first error message for privacy reasons.
I tried quitting Xcode and restarting my computer but the error persisted. Any help on resolving this would be greatly appreciated.
Hi,
I have the following code:
struct Loading: View {
var body: some View {
Text("Loading...")
.onAppear {
print("test")
}
}
}
The view is on the screen, however the print statement doesn't run. Why would this be? Any help would be greatly appreciated.
Hi,
As AppStorage does not support arrays, I found an extension online that allows for handling arrays of strings with AppStorage. However, in my use case, I need to handle arrays of boolean values. Below is the code. Any help would be greatly appreciated.
extension Array: RawRepresentable where Element: Codable {
public init?(rawValue: String) {
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode([Element].self, from: data)
else {
return nil
}
self = result
}
public var rawValue: String {
guard let data = try? JSONEncoder().encode(self),
let result = String(data: data, encoding: .utf8)
else {
return "[]"
}
return result
}
}
Hi,
I'd like to call an Async function upon a state change or onAppear() but I'm not sure how to do so. Below is my code:
.onAppear() {
if !subscribed {
await Subscriptions().checkSubscriptionStatus()
}
}
class Subscriptions {
var subscribed = UserDefaults.standard.bool(forKey: "subscribed")
func checkSubscriptionStatus() async {
if !subscribed {
await loadProducts()
}
}
func loadProducts() async {
for await purchaseIntent in PurchaseIntent.intents {
// Complete the purchase workflow.
await purchaseProduct(purchaseIntent.product)
}
}
func purchaseProduct(_ product: Product) async {
// Complete the purchase workflow.
do {
try await product.purchase()
}
catch {
// Add your error handling here.
}
// Add your remaining purchase workflow here.
}
}