NSInteger Property没有增加

时间:2015-10-04 18:42:45

标签: ios swift core-data

我是Swift的初学程序员。我正在创建一个应用程序,您只需单击一个按钮,您的金额就会增加。

金额目前是核心数据实体。我有一个问题,因为我的金额只增加到值1.当它等于1时我按下按钮它不会增加。

我的ViewController

import UIKit
import CoreData

class ClickerViewController: UIViewController {

    @IBOutlet weak var moneyStatusLabel: UILabel!


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

        let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext

        let request = NSFetchRequest(entityName: "Money")

        let results = try? context.executeFetchRequest(request)

    }

    @IBAction func moneyClicked(sender: AnyObject) {
        let context = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
        let money = NSEntityDescription.insertNewObjectForEntityForName("Money", inManagedObjectContext: context) as! Money

        money.amount += 1
        print(money.amount)
        moneyStatusLabel.text = String(money.amount)
    }


}

我的核心数据文件

NSManagedSubclass

货币+ CoreDataProperties

import Foundation
import CoreData

extension Money {

    @NSManaged var amount: NSInteger

}

货币

import Foundation
import CoreData

class Money: NSManagedObject {


}

数据模型: http://i.stack.imgur.com/BwfUY.png

0 个答案:

没有答案