Post

Replies

Boosts

Views

Activity

Struct Array Filter Problem
Hey guys, first i have to say i'm new to swift. I think it's easy for you to solve my problem, but i got stuck. Here is the code: ................................................................................................. struct box { var ID = "" var a = 0.0 var b = 0.0 var c = 0.0 var d = 0.0 } var boxArray = [box] () var newBox = box() print("Please enter ID: ", terminator: "") newBox.ID = String(readLine()!) let filteredArray = boxArray.filter{$0 == newBox.ID} filteredArray.isEmpty ... ................................................................................................... I want to make sure, that you can't enter an ID that is already used. Above is my attempt to code this, but just creates errors. How can I filter the boxArray only for String-type ? This is the error: Referencing operator function '==' on 'StringProtocol' requires that 'box' conform to 'StringProtocol'
2
0
652
Nov ’21
Struct Array Filter Problem
Hey guys, first i have to say i'm new to swift. I think it's easy for you to solve my problem, but i got stuck. Here is the code: ................................................................................................. struct box { var ID = "" var a = 0.0 var b = 0.0 var c = 0.0 var d = 0.0 } var boxArray = [box] () var newBox = box() print("Please enter ID: ", terminator: "") newBox.ID = String(readLine()!) let filteredArray = boxArray.filter{$0 == newBox.ID} filteredArray.isEmpty ... ................................................................................................... I want to make sure, that you can't enter an ID that is already used. Above is my attempt to code this, but just creates errors. How can I filter the boxArray only for String-type ? This is the error: Referencing operator function '==' on 'StringProtocol' requires that 'box' conform to 'StringProtocol'
Replies
2
Boosts
0
Views
652
Activity
Nov ’21