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 Creating a Data Model Refactoring Into a Model

After setting up an array in the newer swift file, I get two errors

"consecutive declarations on a line must be separated by ;" "Expected declaration"

Ben Griffith
Ben Griffith
5,808 Points

Can you post your code?

import Foundation

struct IslamicFacts {

let factsArray = [
    "Invention: The world's first university was a founded by a Muslim women by the name of Fatima Al-Fihri, in Morocco. Yes, a woman!",
    "Invention: That coffee you had earlier, yes, it has Muslim origins. The earliest historical evidence for coffee drinking goes back to Yemen, early 15 th century.",
    "Invention: Algebra was founded by a Muslim scientist and mathematician, Muhammad ibn Musa al- Khawarizmi, in 9th century. The word algebra is derived from his book 'al-jabr.'",
    "Invention: The first flying machine was designed by a Muslim inventor, Abbas ibn Firnas, hundreds of years before Leonardo da Vinci's made his own drawings.",
    "The hajj is an annual pilgrimage to Masjid Al Haram in Makkak. It gathers nearly 3 million Muslims from all over the world, making it the largest gathering in the world!",
    "The Quran is the only scripture that remains untouched and unaltered from its original form.",
    "The Quran is the most memorized text in the world: memorized by nearly populations in millions.",
    "The first person to embrace Islam after Prophet Muhammad (peace be upon him) was a woman, his wife: Khadija.", "Muhammad is the most common name in the world.",
    "No Islam doesn't oppress woman: Islam grants women many rights in the home and in society. Among them are the right to earn money, to financial support, to own property, to an education, to an inheritance, to being treated kindly, to vote, to a bridal gift, to keep their maiden name, to worship in a mosque, to a divorce, and so on."
]

}

My swift file reads:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var islamFactLabel: UILabel!
let islamicFacts = IslamicFacts()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func showAnotherFact() {
   islamFactLabel.text = islamicFacts.factsArray[1]
}

}

And, I'm using this course: http://teamtreehouse.com/library/build-a-simple-iphone-app-with-swift/creating-a-data-model/refactoring-into-a-model

1 Answer

I just ran into the same problem.

I went into the FactBook.swift file and made the array type 'String' explicit:

let factsArray : [String] = {

This made the errors go away.

HTH.

Clark