将Bool值更改为INT
我呼吁您寻求制作第一个应用程序的帮助。我是白天盲人和视力障碍的老师,正在尝试将应用程序用于我们的学生评估。在此特定部分中,我们正在评估他们的位置/空间技能。我们喜欢使用切换的便捷性,但是我很难将BOOL值更改为INT,以便获得每个部分的分数。我想要true = 1和false = 0。数值得分将在每个部分下方列出,我已经对其进行了编码。
我试图使用“扩展”来更改值,但要继续遇到错误。我可以将它们全部更改为一个分段的选择器,并接近相同的易用性,但是希望有一个更容易的修复程序,因为我已经编码了其中100台。提前致谢!
struct caneSkills: View {
@State var front = false
@State var behind = false
@State var onTop = false
@State var below = false
@State var between = false
@State var nextTo = false
@State var under = false
@State var onBottom = false
@State var inBack = false
@State var onTheSide = false
var body: some View {
let psScore = (front + behind + onTop + below + between + nextTo + under + onBottom + inBack + onTheSide)
NavigationView {
Form {
Section(header: Text("Positional/Spatial Concepts")) {
Toggle("Behind", isOn: $behind)
Toggle("Below", isOn: $below)
Toggle("In Back", isOn: $inBack)
Toggle("In Between", isOn: $between)
Toggle("In Front", isOn: $front)
Toggle("Next To", isOn: $nextTo)
Toggle("On The Bottom", isOn: $onBottom)
Toggle("On Side", isOn: $onTheSide)
Toggle("On Top", isOn: $onTop)
Group {
Toggle("Under", isOn: $under)
Text("Positional/Spatial Concepts Score: \(psScore) / 10")
.font(.headline)
.foregroundColor(Color.blue)
}
}
}
.navigationTitle("Cane Skills")
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
I am calling for your help on my quest of making my first app. I am a teacher for the blind and visually impaired by day and am trying to make an app to use for our evaluations of students. In this particular section, we are evaluating their Positional/Spatial skills. We like the ease of using a toggle but I am having a hard time changing the bool value to an Int in order to get a score for each section. I would like true = 1 and false = 0. The numerical score will be listed below each section and I already have that coded out.
I have tried to use "Extension" to change the value but keep getting an error. I could change them all to a segmented picker and get close to the same ease of use but was hoping there was an easier fix since I've already coded about 100 of these. Thanks in advance!
struct caneSkills: View {
@State var front = false
@State var behind = false
@State var onTop = false
@State var below = false
@State var between = false
@State var nextTo = false
@State var under = false
@State var onBottom = false
@State var inBack = false
@State var onTheSide = false
var body: some View {
let psScore = (front + behind + onTop + below + between + nextTo + under + onBottom + inBack + onTheSide)
NavigationView {
Form {
Section(header: Text("Positional/Spatial Concepts")) {
Toggle("Behind", isOn: $behind)
Toggle("Below", isOn: $below)
Toggle("In Back", isOn: $inBack)
Toggle("In Between", isOn: $between)
Toggle("In Front", isOn: $front)
Toggle("Next To", isOn: $nextTo)
Toggle("On The Bottom", isOn: $onBottom)
Toggle("On Side", isOn: $onTheSide)
Toggle("On Top", isOn: $onTop)
Group {
Toggle("Under", isOn: $under)
Text("Positional/Spatial Concepts Score: \(psScore) / 10")
.font(.headline)
.foregroundColor(Color.blue)
}
}
}
.navigationTitle("Cane Skills")
}
.navigationViewStyle(StackNavigationViewStyle())
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是为了娱乐,您可以扩展Bool类型并向其添加值属性。然后,您可以简单地创建一个自定义操作员来总结所有BOOL元素:
我还将构建数据
squill
。这样,您就可以拥有一个具有所有技能的数组:Just for fun you can extend Bool type and add a value property to it. Then you can simply create a custom operator to sum all bool elements:
I would also structure the data
Skill
. This way you can have an array with all your skills:我认为您不需要将
bool
转换为int
才能获得总分。您可以使用这种简单的方法获得分数:I don't think you need to convert a
Bool
to anInt
to get the total score. You could get the score using this simple approach: