2016-04-26 59 views
0

我正在使用这款报价应用程序,并且我一直遇到两个只是不想与我合作的错误。它说“类型'businessQuote'没有成员('array'/'dict')”。在以下屏幕截图中,您将看到该行上的错误。关键在于让应用程序在提供的文本字段中显示随机引号。你可以帮我吗?先谢谢你。类型'___'没有会员'array'

Code with the error

我的目标是获得“ImportList”工作

'ImportList' Swift file

如果有这样一个问题,我都忽略了,我将不胜感激,如果你能联系我它。但我真的需要一个答案。再次感谢你。

这里是有错误的代码:

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 

}

}

这与 '阵列' 和 '字典'

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 
} 
} 

谢谢你的代码!

+3

您应该发布代码与您的问题,而不是一个图片的链接 – Amous

+0

对不起,我会编辑它。 –

回答

1

你声明的变量businessQuotes为:

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

但使用businessQuote相反,看看你缺少的 “s” 结尾。拼写错误。以下行应该是:

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

非常感谢。我没有看到这些,我感到很蠢。 –

相关问题