Hello guys!
I am trying to run my application on a physical iPad device. The app is successfully installed and when I run the code, it "Builds successfully", but when it starts, the screen is just dark and on the Xcode file it says "Paused app on iPad".
i don't know what else to do. can anyone help me with this? Thank you!
Post
Replies
Boosts
Views
Activity
Hi there!
can someone help me with this one:
func resetMatrix() {
matrix = Array(repeating: Array(repeating: 0, count: numberOfColumns), count: numberOfRows)
let coordinates = [
(selectedRow1, selectedColumn1),
(selectedRow2, selectedColumn2),
(selectedRow3, selectedColumn3)
]
for (row, column) in coordinates {
matrix[row - 1][column - 1] += 1
}
}
i can't seem to make it work.
i want it to work like this:
If the chosen coordinate in Question 1 is (2,2), it will place the value 1 in the matrix coordinate (2,2). If the chosen coordinate in Question 2 is also (2,2), it will increment the value in the matrix coordinate (2,2) by 1, making it 2. Similarly, if the chosen coordinate in Question 3 is (2,2), it will increment the value in the matrix coordinate (2,2) by 1 again, making it 3.
Thank you!
https://drive.google.com/file/d/1GWV9MYs_X4HG0XT4_-wDPPHdWOFwsRJs/view?usp=sharing
Hi, everyone!
So, I am trying to create an app that is like a survey app. I am new to coding by the way (less than a month)
I have this long-*** code that I am trying to work. Well, it is working except for one more part of the code.
I've been trying to make it work for days now and I cannot seem to figure it out.
I uploaded it in a google drive link above.
This is what it is:
If you try to run this code in Xcode, you can see a thing like this:
The app works like this, users select the pickers beside the Criteria and Relative Risk.
The scores will show as:
Score: 2,4 (just a sample score)
criteria = row
relative risk = column
what I want to happen is that this score will immediately translate as a coordinate in the risk matrix below. There are 21 sets of pickers for this part of the app. The coordinates can have more than 1 value. so if there are 3 scores that have the same coordinate, such coordinate in the matrix should show 3. There can be coordinates with 0.
the initial value in this risk matrix is 0, (you can see 1 in the photo but this was when I tried to manually input the coordinates in the code.)
it is okay if the matrix will update using a button. meaning when the users have completed all the pickers, then they will click on the button to update the matrix.
this is the part that I cannot figure out and I desperately need help.
Thank you!
Hoping someone can help me with this.
Best Regards!
Hey guys, so i am making like a quiz app. each question in the app has 2 answers which are chosen from separate pickers.
import Foundation
import SwiftUI
import UIKit
import PDFKit
struct MatrixViewControllerWrapper: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> MatrixViewController {
return MatrixViewController()
}
func updateUIViewController(_ uiViewController: MatrixViewController, context: Context) {
// Update the view controller if needed
}
}
struct ReinforedSlopeFormView: View {
// Environment variable for managing presentation mode
@Environment(.presentationMode) var presentationMode
// Form input state variables
@State private var settlementPickerIndex = 0
@State private var displacementPickerIndex = 0
@State private var riskIndexPickerIndex1 = 0
@State private var riskIndexPickerIndex2 = 0
let matrixLabelSize: CGFloat = 30.0
let numberOfRows = 5
var body: some View {
NavigationView {
Form {
Group {
// Settlement Section
Section(header: Text("Settlement").font(.title3).bold() ) {
Picker("Criteria", selection: $settlementPickerIndex, content: {
ForEach(0..<ReinforcedQData().settlementChoices.count, id: \.self) { index in
Text(ReinforcedQData().settlementChoices[index])
}
})
.pickerStyle(MenuPickerStyle())
Picker("Relative Risk", selection: $riskIndexPickerIndex1, content: {
ForEach(0..<ReinforcedQData().riskIndexChoices.count, id: \.self) { index in
Text(ReinforcedQData().riskIndexChoices[index])
}
})
.pickerStyle(MenuPickerStyle())
Text("Score: \(ReinforcedQData().settlementScores[settlementPickerIndex]), \(ReinforcedQData().riskIndexScores[riskIndexPickerIndex1])")
}
//Slope Angle - Bedrock
Section(header: Text("Horizontal Displacement").font(.title3).bold() ) {
Picker("Criteria", selection: $displacementPickerIndex, content: {
ForEach(0..<ReinforcedQData().displacementChoices.count, id: \.self) { index in
Text(ReinforcedQData().displacementChoices[index])
}
})
.pickerStyle(MenuPickerStyle())
Picker("Relative Risk", selection: $riskIndexPickerIndex2, content: {
ForEach(0..<ReinforcedQData().riskIndexChoices.count, id: \.self) { index in
Text(ReinforcedQData().riskIndexChoices[index])
}
})
.pickerStyle(MenuPickerStyle())
Text("Score: \(ReinforcedQData().displacementScores[displacementPickerIndex]), \(ReinforcedQData().riskIndexScores[riskIndexPickerIndex2])")
}}
}
}
there are more 19 more sections making 21 questions for this code.
below each section has a text printed as Score: (A,B)
where A and B here are numbers making it look like coordinates.
the picker index values and choices are created in a separate file.
can anyone help me in creating a matrix with those scores as the coordinates?
i have this existing matrix code in a separate swift file:
import SwiftUI
import UIKit
class MatrixViewController: UIViewController {
let matrix = [
["A5", "B5", "C5", "D5", "E5"],
["A4", "B4", "C4", "D4", "E4"],
["A3", "B3", "C3", "D3", "E3"],
["A2", "B2", "C2", "D2", "E2"],
["A1", "B1", "C1", "D1", "E1"],
]
let matrixLabelSize: CGFloat = 30.0
override func viewDidLoad() {
super.viewDidLoad()
setupMatrixView()
}
func setupMatrixView() { . . . }
struct Coordinate {
let row: Int
let column: Int
let value: String
}
// Define the coordinate values
@State var coordinates = [
Coordinate(row: 1, column: 1, value: "A"),
Coordinate(row: 1, column: 2, value: "B")]
struct MatrixViewControllerPreview: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UIViewController {
return MatrixViewController()
}
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
}
}
How can i set up the coordinates here when it the score variable represents the score obtained from the user's choices. It is split into separate values using the comma as a separator. The extracted values are then used to create a new Coordinate object, which is appended to the coordinates array.
i am unsure of how the code should be.
also when for example there are 2 values of the same coordinates, it should show 2 in that coordinate in the matrix view. if there are none, the initial value of each coordinate will be zero.
Your input is greatly appreciated.
Thank you! Best regards!
--from a person who just started learning
hi there!
i got this error when I try to use the simulator:
Swift/ContiguousArrayBuffer.swift:600: Fatal error: Index out of range 2023-07-03 21:53:49.575166+0900 LRAT[72102:3459787] Swift/ContiguousArrayBuffer.swift:600: Fatal error: Index out of range
I've got this really long code and I really am unsure how to shorten it. but, when I try to use the simulator, I choose the pickers and it stops. sometimes it can choose choices in the pickers but when I try to export a pdf, it stops. just freezes.
the choices are in a separate Swift file.
I need help.
The following is the code for this particular file(very incomplete).
import SwiftUI
import UIKit
import PDFKit
struct NaturalSlopeFormView: View {
@Environment(\.presentationMode) var presentationMode
@State private var location: String = ""
@State private var evaluators: [String] = []
@State private var isDatePickerShown = false
@State private var selectedDate = Date()
@State private var slopeAnglePickerIndex = 0
//until the 31st variable
@State private var unclearManagementPickerIndex = 0
@State private var relativeRiskPickerIndex1 = 0
//until #31
@State private var relativeRiskPickerIndex31 = 0
@State private var isFormSaved = false
@State private var isExportingPDF = false
@State private var evaluationsCountForCurrentDay = 0
var body: some View {
NavigationView {
Form {
Group {
Section(header: Text("Date")) {
DatePicker() {Text("Select a Date")}}
Section(header: Text("Location")) {
TextField("Location", text: $location)}
Section(header: Text("Evaluators")) {
ForEach(evaluators.indices, id: .self) { index in
TextField("Evaluator (index + 1)", text: $evaluators[index])}
Button(action: addEvaluator) {
Label("Add Evaluator", systemImage: "plus.circle")
}
}
}
Group {
Section(header: Text("Slope Angle").font(.title3).bold() ) {
Picker("Criteria", selection: $slopeAnglePickerIndex, content: {
ForEach(0..<QuestionData().slopeAngleChoices.count, id: .self) { index in
Text(QuestionData().slopeAngleChoices[index])}})
.pickerStyle(MenuPickerStyle())
Picker("Relative Risk", selection: $relativeRiskPickerIndex1, content: {
ForEach(0..<QuestionData().relativeRiskChoices.count, id: .self) { index in
Text(QuestionData().relativeRiskChoices[index]) }})
.pickerStyle(MenuPickerStyle())
Text("Score: (QuestionData().slopeAngleScores[slopeAnglePickerIndex]), (QuestionData().relativeRiskScores[relativeRiskPickerIndex1])") }
// Save Button
Button(action: saveForm) {
HStack {
Spacer()
Text("Save Form")
Spacer()
}}
.disabled(isFormSaved)
}
.navigationBarItems(leading:
HStack {
Image("knu") // Replace "knulogo" with your actual image name
.resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 35)
Text("Natural Slope Evaluation")
.font(.title3)
.bold()
},
trailing: Button(action: exportToPDF) {
Image(systemName: "square.and.arrow.up")})}}
func exportToPDF() {
let pdfData = createPDF()
let referenceNumber = generateReferenceNumber()
let fileURL = FileManager.default.temporaryDirectory.appendingPathComponent("\(referenceNumber).pdf")
do {
try pdfData.write(to: fileURL)
isExportingPDF = true
let activityViewController = UIActivityViewController(
activityItems: [fileURL],
applicationActivities: nil
)
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let mainWindow = windowScene.windows.first {
mainWindow.rootViewController?.present(activityViewController, animated: true, completion: nil)}
isExportingPDF = false
} catch {print("Failed to write PDF file: (error.localizedDescription)")
}
}
func createPDF() -> Data {
let pdfMetaData = [
kCGPDFContextCreator: "Natural Slope Evaluation App",
kCGPDFContextAuthor: "Your Name",
kCGPDFContextTitle: "Natural Slope Evaluation Form"
]
let format = UIGraphicsPDFRendererFormat()
format.documentInfo = pdfMetaData as [String: Any]
let data = renderer.pdfData { (context) in
context.beginPage()
let titleFont = UIFont.systemFont(ofSize: 18.0, weight: .bold)
let titleAttributes: [NSAttributedString.Key: Any] = [
.font: titleFont]
let textFont = UIFont.systemFont(ofSize: 12.0)
let textAttributes: [NSAttributedString.Key: Any] = [
.font: textFont]
let photo = UIImage(named: "knu3")
let photoRect = CGRect(x: 20, y: 20, width: 250, height: 80)
photo!.draw(in: photoRect)
let titleText = NSAttributedString(
string: "Natural Slope Evaluation Form",
attributes: titleAttributes )
titleText.draw(at: CGPoint(x: 300, y: 20))
let referenceNumberText = NSAttributedString(
string: "Reference Number: (generateReferenceNumber())",
attributes: textAttributes)
referenceNumberText.draw(at: CGPoint(x: 300, y: 50))
let dateText = NSAttributedString(
string: "Date: \(formattedDate())",
attributes: textAttributes)
dateText.draw(at: CGPoint(x: 300, y: 70))
let locationText = NSAttributedString(
string: "Location: \(location)",
attributes: textAttributes)
locationText.draw(at: CGPoint(x: 300, y: 90))
let evaluatorsText = NSAttributedString(
string: "Evaluators:\n\(formattedEvaluators())",
attributes: textAttributes )
evaluatorsText.draw(at: CGPoint(x: 300, y: 110))
// Create a PDF document
let pdf = PDFDocument()
let page = PDFPage()
//code
var currentPosition = CGPoint(x: 20, y: 170)
let relativeRiskOptions = ["A", "B", "C", "D", "E"]
let tableData: [(String, Int, String)] = [
("Slope Angle", slopeAnglePickerIndex, relativeRiskOptions[relativeRiskPickerIndex1]),
//until #31st variable
]
}
struct NaturalSlopeFormView_Previews: PreviewProvider {
static var previews: some View {
NaturalSlopeFormView()
}
}
This is the error that shows:
"'init(destination:tag:selection:label:)' was deprecated in iOS 16.0: use NavigationLink(value:label:) inside a List within a NavigationStack or NavigationSplitView"
I can't seem to get past these. Can anyone help me with this?
Thank you a bunch!
import SwiftUI
struct FileView: View {
@Environment(.presentationMode) var presentationMode
let forms = [
"Natural Slope Evaluation Form",
"Artificial Slope Evaluation Form",
"Reinforced Slope Evaluation Form"
]
@State private var isFormSelected = false
@State private var selectedForm: String? = nil
var body: some View {
NavigationView {
VStack {
List(forms, id: \.self) { form in
NavigationLink(destination: formView(for: form), tag: form, selection: binding(for: form)) {
Text(form)
}
}
}
}
}
private func formView(for form: String) -> some View {
if form == "Natural Slope Evaluation Form" {
return AnyView(NaturalSlopeFormView())
} else if form == "Artificial Slope Evaluation Form" {
// Handle other form views
} else if form == "Reinforced Slope Evaluation Form" {
// Handle other form views
}
return AnyView(EmptyView())
}
private func binding(for form: String) -> Binding<String?> {
Binding<String?>(
get: { selectedForm },
set: { newValue in
if newValue != selectedForm {
selectedForm = newValue
isFormSelected = newValue != nil
}
}
)
}
}
extension String: Identifiable {
public var id: String {
return self
}
}
struct FileView_Previews: PreviewProvider {
static var previews: some View {
FileView()
}
}
Hello!
I wonder what is wrong with my code:
when I add a new line of text after the text "purpose", it says EXTRA ARGUMENT IN CALL.
i can't seem to figure out why.
I also wanted to format the paragraphs as "justified"
this is the snippet of the code:
also, I am just starting to learn to code (I've started this just less than a week ago, your input would greatly be appreciated)
Thank you!
struct TableViewCell1Content: View {
var body: some View {
ScrollView {
VStack(alignment: .center, spacing: 20) {
Image("natural")
.resizable()
.cornerRadius(25)
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 500)
.padding(.bottom, 10)
Text("Natural Slope")
.font(.largeTitle)
.underline()
Text("Paragraph 1 over here . . . . . long 300-words at least")
.font(.body)
.multilineTextAlignment(.leading)
.lineSpacing(5)
.padding(.horizontal, 40)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom, 30)
Image("artificial")
.resizable()
.cornerRadius(25)
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 500)
.padding(.bottom, 10)
Text("Artificial Slope")
.font(.largeTitle)
.underline()
Text("another paragraph in this area containing 300 words")
.font(.body)
.multilineTextAlignment(.leading)
.lineSpacing(5)
.padding(.horizontal, 40)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom, 30)
Image("reinforced")
.resizable()
.cornerRadius(25)
.aspectRatio(contentMode: .fit)
.frame(maxWidth: 500)
.padding(.bottom, 10)
Text("Reinforced Slope and Gabions")
.font(.largeTitle)
.underline()
Text("another paragraph words words words words words")
.font(.system(size:20))
.multilineTextAlignment(.leading)
.lineSpacing(5)
.padding(.horizontal, 50)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom, 50)
//this part should show the purpose and scope
Text("Purpose")
.font(.largeTitle)
.underline()
Text("this should be a single paragraph explaining the purpose of this app")
}
.frame(maxWidth: .infinity)
.padding()
.alignmentGuide(HorizontalAlignment.center) { _ in
UIScreen.main.bounds.size.width / 2 / 2 // Align VStack at the center horizontally
}
}
.background(Color.brown.opacity(0.3))
}
}