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

Strange error

it shows 5 errors at this part of code:

func randomFact () -> String {
  let unsignedArrayCount  = UInt32(factsArray.count)
        func randomFact() -> String {
return factsArray[Int((arc4random_uniform(unsignedArrayCount))]
        }

1) Expected ',' separator
2)Expected expression in a list of expressions
3)Expected ')' in an expression list
4)Expected expression in a list of expressions
5)Expected ']' in an expression list

// This is the entire code

import Foundation

struct FactBook {
    let factsArray = [
        "Ckemi",
        "Ky eshte nje aplikacion i bere ne gjuhen programuese Swift.",
        "Gjuha programuese Swift eshte nje gjuhe moderne,fleksibel dhe e sigurt.",
        "Ajo u krijua nga kompania Apple ne vitin 2014 ",
        "Ky aplikacion ka si qellim te nxise dhe te promovoje kulturen e qyteteve te Shqiperise",
        "Ky projekt eshte konceptuar te vihet ne pune nga Bashkite dhe zonat e tyre perkatese"

    ]

    func randomFact () -> String {

        let unsignedArrayCount  = UInt32(factsArray.count)
        func randomFact() -> String {
return factsArray[Int((arc4random_uniform(unsignedArrayCount))]
        }


    }
}

2 Answers

I think this is what the function is supposed to look like:

func randomFact () -> String {
  let unsignedArrayCount  = UInt32(factsArray.count)
  return factsArray[Int(arc4random_uniform(unsignedArrayCount))]
}

See the difference?

What is the difference?

Two things. first you had this line in the middle of the function:

func randomFact() -> String {

That will cause an error without a closing brace, which you where missing.

You also had an extra parentheses at the beginning of arc4random_uniform(unsignedArrayCount). You had two instead of one.

Thank you a lot.