Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Greg Jones
Greg Jones
2,417 Points

Large Struct Array will not compile

I have tried to develop an app where I pull information from a struct. When I have a small number of arrays, the app will compile, but if I have more than about 10 arrays Xcode will not compile at all.

data model is as follows:

ExerciseType.swift
import Foundation
import UIKit

struct ExerciseTypes {

    var title: String?
    var description: String?
    var imageIcon: UIImage?

    init(index: Int) {

let exerciseType = ExercisesModel().exerciseType
        let exerciseDictionary = exerciseType(index)
        title = exerciseDictionary["title"]!
        description = exerciseDictionary["description"]!
        let exImageIcon: String = exerciseDictionary["imageIcon"]!
        imageIcon = UIImage(named: exImageIcon)
        }
}

which draws information from

struct ExercisesModel {

    let exerciseType = [
        ["title": "Exercise Type 1",
            "description": "Exercise Type 1 Description",
            "imageIcon": "s",
        ],

        ["title": "Exercise Type 2",
            "description": "Exercise Type 2 Description",
            "imageIcon": "f"],

        ["title": "Exercise Type 3",
            "description": "Exercise Type 3 Description",
            "imageIcon": "b"],

        ["title": "Exercise Type 4",
            "description": "Exercise Type 4 Description",
            "imageIcon": "a"],
    ]
}

Any hints on changing the data structure or what am I missing?

Patrick Li
Patrick Li
2,434 Points

Hmmm... It seems like it should work. Whats your definition of a small number of arrays?

Greg Jones
Greg Jones
2,417 Points

As shown above, there are four arrays of key value pairs. If I add around 10-12 arrays of key value pairs, the compiler will sit on these files and not move forward. When I cancel the compiler, it states there were no errors.

Patrick Li
Patrick Li
2,434 Points

Is your computer slow?

Patrick Li
Patrick Li
2,434 Points

Is your computer slow?

Greg Jones
Greg Jones
2,417 Points

It is definitely an older computer and slow at times, but have not had any issues in the past with compiling or using other programs.

MacBook Pro (mid 2009) Processor 2.8Ghz Core 2 Duo Memory 8 GB 1067 Mhz DDR3 Graphics GeForce 9400m 256MB

Time for an upgrade?

Patrick Li
Patrick Li
2,434 Points

It may be that because the computer is slow, the thread cannot keep up, and because the thread has to run other things at once, if it is not synchronized, it could cause an error. However, take this as a grain of salt because it may not be true. It has happened to me several times on my slower computer.

1 Answer

Patrick Li
Patrick Li
2,434 Points

Is your computer slow?