質問編集履歴
3
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
// エンティティを取得するメソッド
|
62
62
|
|
63
|
-
- (New
|
63
|
+
- (NewModel *)getCoreData:(NSManagedObjectContext *)context {
|
64
64
|
|
65
65
|
|
66
66
|
|
@@ -104,7 +104,7 @@
|
|
104
104
|
|
105
105
|
|
106
106
|
|
107
|
-
New
|
107
|
+
NewModel *managedObject = [NSEntityDescription insertNewObjectForEntityForName:text inManagedObjectContext:context];
|
108
108
|
|
109
109
|
managedObject.applicationNumber = str;
|
110
110
|
|
@@ -126,7 +126,7 @@
|
|
126
126
|
|
127
127
|
|
128
128
|
|
129
|
-
New
|
129
|
+
NewModel *str = [NewModel getCoreData:context];
|
130
130
|
|
131
131
|
if(str == nil){
|
132
132
|
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,6 +58,46 @@
|
|
58
58
|
|
59
59
|
```objective-c
|
60
60
|
|
61
|
+
// エンティティを取得するメソッド
|
62
|
+
|
63
|
+
- (NewData *)getCoreData:(NSManagedObjectContext *)context {
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:text inManagedObjectContext:context];
|
68
|
+
|
69
|
+
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
fetchRequest.entity = entityDescription;
|
74
|
+
|
75
|
+
NSError *error = nil;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
NSArray *result = [context executeFetchRequest:fetchRequest error:&error];
|
80
|
+
|
81
|
+
if([result count] == 0){
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
return nil;
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
return [result objectAtIndex:0];
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
61
101
|
//NSString型のメンバ変数textに対し文字列を保存するメソッド
|
62
102
|
|
63
103
|
- (void)insertText:(NSManagedObjectContext *)context :(NSString *)str{
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
Objective-Cでcoredata
|
1
|
+
Objective-Cでcoredataを使って値を保存したり、
|
2
2
|
|
3
3
|
その値を取り出したりしたいです。
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
画像のように、xcdatamodel
|
7
|
+
画像のように、.xcdatamodelにエンティティを追加
|
8
8
|
|
9
9
|
![イメージ説明](106418e1fa24a1e8f5991dd80ef47d82.png)
|
10
10
|
|