即使输入了require代码,我仍然会收到错误。我错过了什么?
class ViewController: UIViewController, SKPaymentTransactionObserver, SKProductsRequestDelegate, GADBannerViewDelegate {
@IBOutlet weak var txtYearlyIncome: UITextField!
@IBOutlet weak var sldPercentSaved: UISlider!
@IBOutlet weak var lblPercent: UILabel!
@IBOutlet weak var lblWeeklySaved: UILabel!
@IBOutlet weak var lblMonthlySaved: UILabel!
@IBOutlet weak var lblYearlySaved: UILabel!
@IBOutlet weak var lblSaved25: UILabel!
@IBOutlet weak var btnRemoveAds: UIButton!
@IBOutlet weak var bannerView: GADBannerView!
@IBOutlet weak var lblAdsRemoved: UILabel!
var yearlyIncomeString = ""
var yearlyIncomeFloat : Float = 0.0
var percent : Float = 0.0
var weeklySaved : Float = 0.0
var MonthlySaved : Float = 0.0
var YearlySaved : Float = 0.0
var Saved25 : Float = 0.0
var decimalValue : Float = 0.0
var product: SKProduct!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.bannerView.adUnitID = "ca-app-pub-3042973809533220/1135061595"
self.bannerView.rootViewController = self
let request : GADRequest = GADRequest ()
self.bannerView.loadRequest (request)
self.bannerView.hidden = true
self.bannerView.delegate = self
btnRemoveAds.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
let products = response.products
if (products.count != 0)
{
product = products[0] as SKProduct
}
btnRemoveAds.hidden = true
if (NSUserDefaults.standardUserDefaults().objectForKey("Ads") == nil)
{
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
self.getProductInfo();
}
if let status: AnyObject! = NSUserDefaults.standardUserDefaults().objectForKey("Ads"){
if status as! NSString == "purchased" {
self.bannerView.removeFromSuperview()
self.btnRemoveAds.hidden = true;
self.btnRemoveAds.userInteractionEnabled = false
}
else {
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
self.getProductInfo()
}
}
}
func getProductInfo(){
if SKPaymentQueue.canMakePayments(){
let productID:NSSet = NSSet(object:"smmremoveads")
let request:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
request.delegate = self
request.start()
}
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]){
for transaction:AnyObject in transactions {
if let trans:SKPaymentTransaction = transaction as? SKPaymentTransaction{
switch trans.transactionState {
case .Purchased:
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
storePurchase()
lblAdsRemoved.text = "Ads Removed!"
break
case .Failed:
SKPaymentQueue.defaultQueue().finishTransaction(transaction as! SKPaymentTransaction)
break
case .Restored:
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
break
default:
break
}
}
}
}
func storePurchase () {
NSUserDefaults.standardUserDefaults().setObject("purchased", forKey: "Ads")
self.bannerView.removeFromSuperview()
self.btnRemoveAds.hidden = true
self.btnRemoveAds.enabled = false
lblAdsRemoved.text = "Ads Removed"
}
}
@IBAction func sldPercentSavedACTION(sender: UISlider) {
takeINData()
calculate()
}
@IBAction func btnRemoveAdsACTION(sender: UIButton) {
}
@IBAction func btnClearACTION(sender: UIButton) {
clear()
}
func takeINData () {
if txtYearlyIncome.text == ""{
txtYearlyIncome.text = "10000"
}
yearlyIncomeString = txtYearlyIncome.text!
yearlyIncomeFloat = Float(yearlyIncomeString)!
percent = sldPercentSaved.value
}
func calculate () {
YearlySaved = yearlyIncomeFloat * percent
MonthlySaved = YearlySaved / 12
weeklySaved = YearlySaved / 52
Saved25 = YearlySaved * 25
print()
}
func print () {
percent = percent * 100
let sPercent = String(format: "%0.0f", percent)
let sWeekly = String(format: "%0.0f", weeklySaved)
let sMonthly = String(format: "%0.0f", MonthlySaved)
let sYearly = String(format: "%0.0f", YearlySaved)
let sSaved25 = String(format: "%0.0f", Saved25)
lblPercent.text! = "\(sPercent)%"
lblWeeklySaved.text = "$\(sWeekly)"
lblMonthlySaved.text = "$\(sMonthly)"
lblYearlySaved.text! = "$\(sYearly)"
lblSaved25.text = "$\(sSaved25)"
}
func clear () {
txtYearlyIncome.text! = ""
lblWeeklySaved.text = "$"
lblMonthlySaved.text = "$"
lblYearlySaved.text! = "$"
lblSaved25.text = "$"
lblPercent.text! = "0%"
}
func hideKeyboard () {
txtYearlyIncome.resignFirstResponder()
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
hideKeyboard()
}
func round () {
}
}
答案 0 :(得分:0)
在我看来,你有一个缺少的右大括号,但很难分辨,因为你的代码格式很差(我马上就会解决这个问题!)
问题在于:
func getProductInfo() {
if SKPaymentQueue.canMakePayments() {
let productID:NSSet = NSSet(object:"smmremoveads")
let request:SKProductsRequest = SKProductsRequest(productIdentifiers: productID as! Set<String>)
request.delegate = self
request.start()
}
func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]){
for transaction:AnyObject in transactions {
请注意getProductInfo
如何打开两个括号({)并仅关闭一个?这就是问题:在func paymentQueue
之前你需要一秒钟。