2016-04-26 12 views
0

私はこの引用アプリケーションで作業していますが、私は協力したくない2つのエラーに陥っています。 "タイプ 'businessQuote'にはメンバーがありません( 'array'/'dict')。次のスクリーンショットでは、行にエラーが表示されます。全体のポイントは、提供されたテキストフィールドにランダムな見積もりを表示するようにアプリを取得することです。手伝っていただけませんか?前もって感謝します。タイプ '___'にはメンバ '配列'がありません

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

ありがとうございます。私はそれを見ていないためにとても愚かであると感じます。 –

関連する問題