Learn Courses My Dashboard

Getting an error of Thread 1 bounds fail

I keep on getting this error message when I’m simulating. Wanted to see if someone can help me figure this out.
it is in the appdelegate.swift

Thread 1: “*** __boundsFail: index 28 beyond bounds [0 … 27]”

@main       Thread 1: "*** __boundsFail: index 28 beyond bounds [0 .. 27]"
class AppDelegate: UIResponder, UIApplicationDelegate {

Very difficult to give you advice without seeing some code so that we know what your App does, whether it uses any third party frameworks etc etc.

I have added firebase. Sorry I am new to this and trying to figure out where exactly the issue is coming from

Are you using UIKit (storyboard) or SwiftUI?

I am using storyboard

So my guess is that you have a tableView?

yes I do, a couple of them

My thinking is that you have an array that contains, say, 20 items and your tableView is accessing an index that is outside the range of array indexes such as the 21st row which does not exist.

Have you placed any breakpoints in your code to try and identify at what point the code accesses an array index out of range?

It might help if you paste your code for your ViewController that contains the tableView.

Paste your code in as text, rather than providing a screenshot.

To format the code nicely, place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code. Like this:

Code goes here

The 3 back-ticks must be the ONLY characters on the line. The back-tick character is located on the same keyboard key as the tilde character ~ (which is located below the Esc key).

Alternatively after you paste in your code, select that code block and click the </> button on the toolbar. This does the same thing as manually typing the 3 back ticks on the line above and below your code.

This also makes it easier for anyone assisting as they can copy the code and carry out some testing.

oh ok I see, No I have not placed any breakpoints yet, but I am currently using the simulator again to see when this is being triggered.

This is the only coding I have done so far.

**class** FruitsTableViewController: UITableViewController {

**@IBOutlet** **weak** **var** apple: UIButton!

**@IBOutlet** **weak** **var** apricot: UIButton!

**@IBOutlet** **weak** **var** avocado: UIButton!

**@IBOutlet** **weak** **var** banana: UIButton!

**@IBOutlet** **weak** **var** blackberry: UIButton!

**@IBOutlet** **weak** **var** blueberry: UIButton!

**@IBOutlet** **weak** **var** cherry: UIButton!

**@IBOutlet** **weak** **var** citrusFruit: UIButton!

**@IBOutlet** **weak** **var** coconut: UIButton!

**@IBOutlet** **weak** **var** cranberry: UIButton!

**@IBOutlet** **weak** **var** date: UIButton!

**@IBOutlet** **weak** **var** elderberry: UIButton!

**@IBOutlet** **weak** **var** fig: UIButton!

**@IBOutlet** **weak** **var** gojiBerry: UIButton!

**@IBOutlet** **weak** **var** grape: UIButton!

**@IBOutlet** **weak** **var** kiwi: UIButton!

**@IBOutlet** **weak** **var** mango: UIButton!

**@IBOutlet** **weak** **var** melon: UIButton!

**@IBOutlet** **weak** **var** mulberry: UIButton!

**@IBOutlet** **weak** **var** peach: UIButton!

**@IBOutlet** **weak** **var** pear: UIButton!

**@IBOutlet** **weak** **var** pineapple: UIButton!

**@IBOutlet** **weak** **var** plum: UIButton!

**@IBOutlet** **weak** **var** pomegranate: UIButton!

**@IBOutlet** **weak** **var** raspberry: UIButton!

**@IBOutlet** **weak** **var** strawberry: UIButton!

**override** **func** viewDidLoad() {

**super** .viewDidLoad()

// Uncomment the following line to preserve selection between presentations

// self.clearsSelectionOnViewWillAppear = false

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.

// self.navigationItem.rightBarButtonItem = self.editButtonItem


// MARK: **- Table view data source**

**override** **func** numberOfSections(in tableView: UITableView) -> Int {

// #warning Incomplete implementation, return the number of sections

**return** 1


**override** **func** tableView( **_** tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

// #warning Incomplete implementation, return the number of rows

**return** 30


I don’t see an array of items defined anywhere in your code.

You have a whole lot of buttons created so I am curious to know what you are trying to do. Can you explain what you want to do and I’ll try to give you some guidance on how you should go about coding it.

So this is basically a menu item. When each button is clicked it will direct it to a page that is corresponding to that button. For example when apple is clicked it will take it to the apple page. (hope I made sense)

So do you want the list of fruit to appear in a table such that you tap on a row and it presents you a screen that has more details about that item of fruit?

yes, exactly.

I have 28 items/rows

OK then the first thing to do is define an array that is of type String with the list of fruits.

var allFruit = ["apple", "apricot", "avocado", "banana"........]

That array becomes your source of data that drives the tableView.

I’ll create a bit of code and show you how you should lay it out. I’ll get back to you in a short while.

Oh ok! Thank you so much! I appreciate all your help!

Here is a pretty basic App that has a table View so that you can see how to code a table View and how to configure your storyboard.

I have not added a second screen that would be a DetailView. Just see if you can understand what has been done thus far.

I just got a chance to see it. So instead of making each one a button, I would list all as var allFruit and then make the count in a way that it returns as the amount of fruits I had listed under var allFruit