duncan.wallaceiv@nike.com:
I will check this out. Thanks!
Post
Replies
Boosts
Views
Activity
Claude31:
I've tried this and it gave me three errors: Cannot convert value of type '[Any]' to specified type 'Binding<[Card]?>'
Extraneous argument label 'wrappedValue:' in call
Value of optional type 'Binding<[Card]>?' must be unwrapped to refer to member 'wrappedValue' of wrapped base type 'Binding<[Card]>'
Anything I missed?
By the way I totally messed up my post, this is AddView:
import SwiftUI
struct AddView: View {
@State var name: String = ""
@State var id: String = ""
@State var cname: String = ""
@State var qrcode = true
var body: some View {
NavigationView {
VStack {
CardView(name: name, id: id)
TextField("Name", text: $name)
.textFieldStyle(RoundedBorderTextFieldStyle())
.shadow(radius: /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/)
TextField("ID", text: $id)
.textFieldStyle(RoundedBorderTextFieldStyle())
.shadow(radius: /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/)
Toggle(isOn: $qrcode) {
if qrcode {
Text("QR Code")
} else {
Text("Barcode")
}
}
TextField("Card Name", text: $cname)
.textFieldStyle(RoundedBorderTextFieldStyle())
.shadow(radius: /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/)
Button(action: {}) {
Text("Create")
.bold()
}
.disabled(self.name.isEmpty self.id.isEmpty self.cname.isEmpty)
.foregroundColor(.white)
.padding()
.padding(.horizontal, 100)
.background(Color.accentColor)
.cornerRadius(10)
}.padding()
.navigationTitle(cname)
.navigationBarTitleDisplayMode(.inline)
}
}
}
struct AddView_Previews: PreviewProvider {
static var previews: some View {
AddView()
}
}
Can't provide an image (Apple's policy, I guess), but here's a rough area of where it is:
struct CardsView: View {
@State private var editMode = EditMode.inactive
@Binding private var cards: [Card] = []
private static var count = 0
And where @Binding is is where the error occurred. To further this, here's the options it provided: Insert "
Chain the optional using '?' to access member 'wrappedValue' only for non-'nil' base values
Force-unwrap using '!' to abort execution if the optional value contains 'nil'
Option 1 does literally nothing while the others add a ? or ! after the empty square brackets of line 3.
How do you want to store the values received from AddView? First off, I probably should have provided the code for CardRow:
import SwiftUI
import CoreImage.CIFilterBuiltins
struct CardRow: View {
let context = CIContext()
let filter = CIFilter.qrCodeGenerator()
let cname: String
let name: String
let id: String
func generateQRCode(from string: String) -> UIImage {
let data = Data(string.utf8)
filter.setValue(data, forKey: "inputMessage")
if let outputImage = filter.outputImage {
if let cgimg = context.createCGImage(outputImage, from: outputImage.extent) {
return UIImage(cgImage: cgimg)
}
}
return UIImage(systemName: "xmark.circle") ?? UIImage()
}
var body: some View {
HStack {
Image(uiImage: generateQRCode(from: id))
.interpolation(.none)
.resizable()
.scaledToFit()
.frame(width: 87.5, height: 87.5)
.cornerRadius(5)
VStack(alignment: .leading) {
Text(cname)
.font(.title)
.bold()
Text(name)
.font(.headline)
.bold()
Text(id)
.font(.subheadline)
}
}
}
}
And second, like I said in my original post, I want the data to pass through CardRow so it can show in the List in CardsView. And I also need to know the right declaration of name, id, cname, and qrcode. Whether it's a let or a var (or neither) and if it's a String or a Double (or neither). Sorry if this is not your answer, I just need some elaboration 😁.
....you need to hold a collection containing name, id, cname and qrcode.
How do you want to have it? I want an HStack with qrcode on the left while on the right there is a VStack showing cname, name, and id respectively.
It would just show that data in the CardRow. The list is calling CardRow with the data:
List {
ForEach(cards) { cards in
NavigationLink(destination: CardFullView(cname: [how AddView() provides cname])) {
CardRow(cname: [how AddView() provides cname], name: [how AddView() provides name], id: [how AddView() provides id])
}
}
.onDelete(perform: onDelete)
.onMove(perform: onMove)
}
CardRow automatically generates a QR code from what id provides.
Define a ObservableObject holding the values and use it as @ObservedObject in CardView I would probably want to do this, but would it just be the CardView that's just the ZStack or CardsView with the List?
You're fine!
Since I'm not too experienced with Swift/SwiftUI yet, I'll need some help ObservableObject...could you help me out?
I'll try this out!
One last thing;
What would I do so (first) it enables the button when you fill in everything and when you (second) press the button, it adds to the list with the completed CardsInfo data?
Sorry for the late reply.
Where is the button?
Where is the list? In AddView, the "Create" button is located at the bottom. Here it is with all its modifiers:
Button(action: {}) {
Text("Create")
.bold()
}.disabled(self.cardInfo.name.isEmpty	self.cardInfo.id.isEmpty	self.cardInfo.cname.isEmpty)
.foregroundColor(.white)
.padding()
.padding(.horizontal, 100)
.background(Color.accentColor)
.cornerRadius(10)
The disabled modifier is disabling it entirely, even if I add a value to the TextFields. I need some way to change that. The || dividers aren't showing because it screws up the code block.
On my second thing, there is no action specified. That's what I'd like to replace with something to have the now completed (and, correct me if I'm wrong) cardInfo to pass through CardRow and end up in the List that is located in CardsView:
List {
ForEach(cards) { cards in
NavigationLink(destination: CardFullView(cname: cardsInfo.newCard.cname)) {
CardRow(cname: cardsInfo.newCard.cname, name: cardsInfo.newCard.name, id: cardsInfo.newCard.id)
}
}
.onDelete(perform: onDelete)
.onMove(perform: onMove)
}
The disabled modifier is disabling it entirely, even if I add a value to the TextFields. I need some way to change that. There's another bug happening with this, as well. Though when initially putting in the info, it doesn't enable the Create button, nor does it update the card preview (CardView) and navigationTitle. But when dismissing it and tapping the add button again, it shows that information and enables the Create button.
On another note, I figured out a way to show the cardInfo data in the list, but it's not the way I want it. I want some way to make it so the Create button executes the onAdd function...and it seems finished from what I've tested.
I've changed it so AddView shows as a Sheet, so it's no longer a NavigationLink. All I need to do is call onAdd, but that function is embedded in CardsView, where the List is located. I want to call that function from AddView, but it's only available in CardsView.
Most parts get cleared, but it seems you have touched your code since then. You're correct, as I was revamping some views and disregarded important parts. That's entirely my fault.
I think it's time for you to start your new thread to solve such another thing. I agree, I feel I've strayed away from what I've been trying to solve...I will start another thread to expand.
Edit:
Here is the new thread:
https://developer.apple.com/forums/thread/670536
I will try this out! Thank you!
This works! But...I need the Create button to dismiss the AddView sheet. I tried adding showSheetView to a shared object but @State is not allowed there. I tried changing it to @Published but it changed nothing.