DrPepperGrad
DrPepperGrad

Reputation: 371

Type '___' has no member 'array'

I am working on this quote app, and I keep running into two errors that just don't want to cooperate with me. It says "Type 'businessQuote' has no member ('array'/'dict')". In the following screen shot, you will see the error on the line. The whole point is to get the app to show a random quote in the text fields provided. Could you please help me? Thank you in advance.

Code with the error

My goal is to get "ImportList" to work

'ImportList' Swift file

If there is another question like this that I have overlooked, I would appreciate it if you could link me to it. But I just really need an answer. Thank you again.

Here's the code with the error:

import Foundation
import UIKit
import Social

class businessQuote: UIViewController {

//============================//
//********** Outlets *********//
//============================//

let utility = Utility()
@IBOutlet weak var quoteDisplay: UILabel!
@IBOutlet weak var authorDisplay: UILabel!
@IBOutlet weak var quoteBackground: UIImageView! //GET BACK TO THIS

//============================//
//********** General *********//
//============================//

let date = NSDate()
var Author: String = ""
var Quote: String = ""

override func viewDidLoad() {
    super.viewDidLoad()

    // Checks if time is greater then 3pm to change background
    let currentTime = utility.currentTime()
    if (currentTime >= 15 ) {
        quoteBackground.image = UIImage(named: "quote_background.png")
    } else {
        quoteBackground.image = UIImage(named:"morning_quote_background.png")
    }
}

//============================//
//********* New Quote ********//
//============================//

   override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    // Generates Random Number
    func randomNumber(arrayLength: Int) -> Int {
        let unsignedArrayCount = UInt32(arrayLength)
        let unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
        let randomNumber = Int(unsignedRandomNumber)


        return randomNumber
    }

    // Importing Quotes plist File
    let businessQuotes = ImportList(FileName: "BusinessList")

    // Selects Quote
    let chosenQuote: String = businessQuote.array[randomNumber(businessQuote
        .count())] as! String
    let chosenAuthor = businessQuote.dict[chosenQuote]! as String

    // Assigns Quote & Author to IBOutlet
    Author = chosenAuthor
    Quote = chosenQuote

    quoteDisplay.text = Quote
    authorDisplay.text = Author.uppercaseString

}

}

This is the code with the 'array' and 'dict'

import Foundation

struct ImportList {
let path: String

init(FileName: String) {
    self.path = NSBundle.mainBundle().pathForResource("\(FileName)", ofType: "plist")!
}

var dict: Dictionary<String, String> {
    return NSDictionary(contentsOfFile: path)! as! Dictionary
}

var array: Array<AnyObject> {
    return [String](arrayLiteral: String(dict.keys) { $0 as AnyObject as! String })
}

func count() -> Int {
    return array.count
}
}

Thank you!

Upvotes: 0

Views: 233

Answers (1)

gagarwal
gagarwal

Reputation: 4244

You have declared variable businessQuotes as:

// Importing Quotes plist File
let businessQuotes = ImportList(FileName: "BusinessList")

But using businessQuote instead, see you are missing "s" at the end. Spelling mistake. Following lines should be:

// Selects Quote
let chosenQuote: String = businessQuotes.array[randomNumber(businessQuotes
    .count())] as! String
let chosenAuthor = businessQuotes.dict[chosenQuote]! as String

Upvotes: 1

Related Questions