Hello to all
How can I index people on the list?
To put the edit button and the favorit items for the list
This method gives me an error :
Fatal error: Unexpectedly found nil while unwrapping an Optional value
import SwiftUI
struct EditContact: View {
@Environment
(\.presentationMode) var presentationMode:Binding<PresentationMode>
@ObservedObject
var CON : Contact
@State
var act = false
// id = UUID()
var char : charContact
var index: Int {
http://CON.contact.firstIndex(where: { $0.id == http://char.id })!
}
@State
var active = false
var body: some View {
NavigationView {
VStack {
Image(systemName: "http://camera.circle.fill")
.padding()
.padding()
.padding()
.font(.system(size: 180))
Spacer()
VStack(alignment: .leading) {
HStack {
Text("Name")
Spacer()
TextField("\(http://self.char.name)", text: $CON.contact[self.index].name)
.padding()
.frame(width: 250, height: 40)
.border(Color.white, width: 1)
}.padding()
HStack {
Text("Title")
Spacer()
TextField("\(self.char.title)", text: $CON.contact[self.index].title)
.padding()
.frame(width: 250, height: 40)
.border(Color.white, width: 1)
}.padding()
HStack {
Text("Company")
Spacer()
TextField("\(http://self.char.company)", text: $CON.contact[self.index].company)
.padding()
.frame(width: 250, height: 40)
.border(Color.white, width: 1)
}.padding()
HStack {
Text("Email")
Spacer()
TextField("\(http://self.char.email)", text: $CON.contact[self.index].email)
.padding()
.frame(width: 250, height: 40)
.border(Color.white, width: 1)
}.padding()
}
Rectangle()
.frame(minWidth: 0, maxWidth: 380, maxHeight: 1)
HStack {
Text("Mobile")
Spacer()
TextField("\(http://self.char.mobile)", text: $CON.contact[self.index].mobile)
.padding()
.frame(width: 250, height: 40)
.border(Color.white, width: 1)
}.padding()
Spacer()
HStack {
Button(action: {
if http://self.CON.contact[self.index].name == "" && http://self.CON.contact[self.index].title == "" && http://self.CON.contact[self.index].company == "" && http://self.CON.contact[self.index].mobile == "" {
self.act = true
}
}){
Text("Save")
.padding()
.frame(width: 150, height: 40)
.border(Color.white, width: 2)
.foregroundColor(.orange)
}
.padding()
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}){
Text("Back")
.padding()
.frame(width: 150, height: 40)
.border(Color.white, width: 2)
.foregroundColor(.orange)
}
}
.alert(isPresented: $act) {
Alert(title: Text("Warning!!"), message: Text("Please enter the details you want to edit or press the Back button."))
}
}.navigationBarTitle("Edit contact",displayMode: .inline)
}.colorScheme(.dark)
}
}
var index: Int {
http://CON.contact.firstIndex(where: { $0.id == http://char.id })!
}