概要と私のNSManagedObjectのサブクラスを接続私ViewController.swift
これはおそらく非常にダム/簡単な質問ですが、それはループを通して私を投げているようです。私はStackOverflow上の私の仲間のアドバイスごとに、 "UsedInfo"エンティティ用のNSManagedObjectサブクラスを作成しました。私の最終的な目標は、このサブクラスを使用してCoreDataにユーザー情報を送信し、後でそれを取得することです。
ISSUE
問題は、私は私の新しいファイルを使用する方法を見つけ出すことができないということです、私のテキストフィールドがどこにある私の「ViewController.swift」ファイルと「UsedInfo + CoreDataProperties.swift」、接続された。下に関連するコードがあります。
ViewController.swiftのコード(SaveButton)
@IBAction func saveButton(sender: AnyObject) {
let appDel: AppDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)
let context:NSManagedObjectContext = appDel.managedObjectContext
let managedContext:NSManagedObjectContext = appDel.managedObjectContext
let entity1 = NSEntityDescription.insertNewObjectForEntityForName("UsedInfo", inManagedObjectContext:context) as NSManagedObject
let one = pickerTextField.text
let two = modelName.text
let three = serialNo.text
let four = YOM.text
let five = engineHours.text
let six = locationOfMachine.text
entity1.setValue(one, forKey: "product")
entity1.setValue(two, forKey:"modelName")
entity1.setValue(three, forKey:"serialNo")
entity1.setValue(four, forKey:"yom")
entity1.setValue(five, forKey:"engineHours")
entity1.setValue(six, forKey:"location")
print(entity1.valueForKey("product"))
print(entity1.valueForKey("modelName"))
print(entity1.valueForKey("serialNo"))
print(entity1.valueForKey("yom"))
print(entity1.valueForKey("engineHours"))
do {
try context.save()
}
catch {
print("error")
}
}
"UsedInfo + CoreDataProperties.swift" のコード
import Foundation
import CoreData
extension UsedInfo {
@NSManaged var engineHours: String?
@NSManaged var location: String?
@NSManaged var modelName: String?
@NSManaged var product: String?
@NSManaged var serialNo: String?
@NSManaged var yom: String?
}
"UsedInfo.swift"
のコードimport Foundation
import CoreData
class UsedInfo: NSManagedObject {
//Insert code here to add functionality to your managed object subclass
}
事前にお世話になりました。私の完全な正義のために残念です。
これはまさに私が探していたものです。ありがとう、トム。私は私の質問がばかげているのを知っている、私はiOSの開発にまったく慣れていない。 – gavsta707