Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Swift Debugging Our App Breakpoints

gökhan sayılgan
gökhan sayılgan
2,285 Points

A bigger array crashes and says: "unable to execute command: Segmentation fault: 11"

i just build an app so smiler to our fun fact example but it has an array that contains more then 1900 sentences inside of it until to get this size it was working well but now array is bigger and gives me " unable to execute command: Segmentation fault: 11" error so what can we do to solve that bug

4 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Based on a quick Google search this appears to be a bug with the Swift compiler. However, it would be helpful to see your code. I know it's large, but could we see how your array is constructed?

gökhan sayılgan
gökhan sayılgan
2,285 Points

import Foundation

struct Dictionary {

var dictionaryArray = ["a broad range = geniş bir alan / yelpaze",
    "a case in point = iyi bir örnek",
    "a couple of = birkaç, iki üç, a few",
    "a day out in the country = dışarıda kırlarda geçirilen bir gün",
    "a desperate situation = vahim bir durum",
    "a full recovery = tam bir iyileşme / düzelme",

//and many other sentences like that over 1900 ]

func randomWord() -> String {

    var unsignedArrayCount = UInt32(dictionaryArray.count)
    var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
    var randomNumber = Int(unsignedRandomNumber)

    return dictionaryArray[randomNumber]
}

}

//when i delete some of units from array it works again and please give me more specific answers rather then google i was checking for a week and can't have an answer

Greg Kaleka
Greg Kaleka
39,021 Points

Can you surround your whole code block like this:

```Swift

[your code]

```

Note, those are back-ticks, not apostrophes. `, not '. You can copy paste directly, if its easier.

gökhan sayılgan
gökhan sayılgan
2,285 Points
import Foundation

struct Dictionary {

var dictionaryArray = ["a broad range = geniş bir alan / yelpaze",
    "a case in point = iyi bir örnek",
    "a couple of = birkaç, iki üç, a few",
    "a day out in the country = dışarıda kırlarda geçirilen bir gün",
    "a desperate situation = vahim bir durum",
    "a full recovery = tam bir iyileşme / düzelme",   
                     //and many other sentences like that over 1900 
     ]

func randomWord() -> String {

    var unsignedArrayCount = UInt32(dictionaryArray.count)
    var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
    var randomNumber = Int(unsignedRandomNumber)

    return dictionaryArray[randomNumber]
       }
}
gökhan sayılgan
gökhan sayılgan
2,285 Points

when i delete some of units from array it works again and please give me more specific answers rather then google i was checking for a week and can't have an answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hm. I'm not sure why that would happen. I still think it's possible it's a Swift compiler error, which means I can't help! I think I would submit a bug report to Apple.

Do you know any Objective-C? It would be interesting to see if the code worked in that language. You wouldn't need to re-write the entire program - just this struct, and a call to the randomWord method...

gökhan sayılgan
gökhan sayılgan
2,285 Points

unfortunately i don't have objective c experience

Jaskirat Singh
Jaskirat Singh
1,652 Points

Did this get solved now?