Here is my whole code, does someone knows how to fix it?
Code (Part 2):
@available(macOS 10.15, *)
struct CallView: View {
@StateObject var friendManager: FriendManager // <<-- CHANGE HERE
@State private var searchText: String = ""
let username: String
@available(macOS 10.15.0, *)
var body: some View {
VStack {
// Search bar
HStack {
TextField("Search", text: $searchText)
.textFieldStyle(RoundedBorderTextFieldStyle())
Button(action: searchForFriends) {
Image(systemName: "magnifyingglass")
.foregroundColor(.blue)
}
}
.padding()
// List of friends
ScrollView {
ForEach(friendManager.friends, id: \.self) { friend in // <<-- CHANGE HERE
HStack {
Text(friend.username)
.font(.body)
.padding(.vertical, 8)
Spacer()
Button(action: {
// Call friend using call library
}) {
Image(systemName: "phone.fill")
.foregroundColor(.blue)
.padding(.vertical, 8)
}
}
}
}
}
}
private func searchForFriends() {
// Search for friends using API or local data
}
}
struct MapView: View {
@available(macOS 10.15.0, *)
@State private var mapRegion = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 43.6, longitude: 1.44), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)) // <<-- Set your region
var body: some View {
Map(coordinateRegion: $mapRegion)
.edgesIgnoringSafeArea(.all)
}
}
struct Friend :Hashable { // <<-- CHANGE HERE
let username: String
}
struct Message : Hashable { // <<-- CHANGE HERE
let text: String
let sender: String
}
@available(macOS 10.15, *)
class FriendManager: ObservableObject {
@Published var friends: [Friend] = []
func addFriend(friend: Friend) {
friends.append(friend)
}
func searchForFriends(searchText: String) -> [Friend] {
// Search for friends using API or local data
return []
}
}
@available(macOS 10.15, *)
class ChatManager: ObservableObject {
@Published var messages: [Message] = []
func addMessage(_ message: Message) { // <<-- CHANGE HERE
messages.append(message)
}
}