国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - IOS - iOS CoreData 增刪改查詳解

iOS CoreData 增刪改查詳解

2021-01-27 16:21肖品 IOS

這篇文章主要為大家詳細(xì)介紹了iOS CoreData 增刪改查的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

最近在學(xué)習(xí)coredata, 因?yàn)轫?xiàng)目開發(fā)中需要,特意學(xué)習(xí)和整理了一下,整理出來(lái)方便以后使用和同行借鑒。目前開發(fā)使用的swift語(yǔ)言開發(fā)的項(xiàng)目。所以整理出來(lái)的是swift版本,oc我就放棄了。 雖然swift3 已經(jīng)有了,目前整理的這個(gè)版本是swift2 的。swift 3 的話有些新特性。 需要另外調(diào)整,后續(xù)有時(shí)間再整理。 

繼承coredata有兩種方式: 

創(chuàng)建項(xiàng)目時(shí)集成

iOS CoreData 增刪改查詳解

這種方式是自動(dòng)繼承在appdelegate里面,調(diào)用的使用需要通過(guò)uiapplication的方式來(lái)獲取appdelegate得到conext。本人不喜歡這種方式,不喜歡appdelegate太多代碼堆在一起,整理了一下這種方式

將coredata繼承的代碼單獨(dú)解耦出來(lái)做一個(gè)單例類 

項(xiàng)目結(jié)構(gòu)圖

iOS CoreData 增刪改查詳解

項(xiàng)目文件說(shuō)明 
coredata核心的文件就是 
1.xpstoremanager(管理coredata的單例類) 
2.coredatademo.xcdatamodeld (coredata數(shù)據(jù)模型文件)
 3.student+coredataproperites.swift和student.swift (學(xué)生對(duì)象) 
4.viewcontroller.swift 和main.storyboard是示例代碼

iOS CoreData 增刪改查詳解

細(xì)節(jié)代碼 

1. xpstoremanager.swift
coredata數(shù)據(jù)管理單例類

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//
 
// xpstoremanager.swift
 
// coredatademo
 
//
 
// created by xiaopin on 16/9/16.
 
// copyright © 2016年 xiaopin.cnblogs.com. all rights reserved.
 
//
 
 
 
import coredata
 
 
 
/// 本地?cái)?shù)據(jù)庫(kù)管理類:默認(rèn)是寫在appdelegate的,可以這樣分離出來(lái)
 
class xpstoremanager {
 
 
 
 //單例寫法
 
 static let shareinstance = xpstoremanager()
 
 
 
 private init() {
 
  
 
 }
 
 
 
 // mark: - core data stack
 
 
 
 lazy var applicationdocumentsdirectory: nsurl = {
 
  // the directory the application uses to store the core data store file. this code uses a directory named "com.pinguo.coredatademo" in the application's documents application support directory.
 
  let urls = nsfilemanager.defaultmanager().urlsfordirectory(.documentdirectory, indomains: .userdomainmask)
 
  print("\(urls[urls.count-1])")
 
  return urls[urls.count-1]
 
 }()
 
 
 
 lazy var managedobjectmodel: nsmanagedobjectmodel = {
 
  // the managed object model for the application. this property is not optional. it is a fatal error for the application not to be able to find and load its model.
 
  let modelurl = nsbundle.mainbundle().urlforresource("coredatademo", withextension: "momd")!
 
  return nsmanagedobjectmodel(contentsofurl: modelurl)!
 
 }()
 
 
 
 lazy var persistentstorecoordinator: nspersistentstorecoordinator = {
 
  // the persistent store coordinator for the application. this implementation creates and returns a coordinator, having added the store for the application to it. this property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
 
  // create the coordinator and store
 
  let coordinator = nspersistentstorecoordinator(managedobjectmodel: self.managedobjectmodel)
 
  let url = self.applicationdocumentsdirectory.urlbyappendingpathcomponent("singleviewcoredata.sqlite")
 
  var failurereason = "there was an error creating or loading the application's saved data."
 
  do {
 
   try coordinator.addpersistentstorewithtype(nssqlitestoretype, configuration: nil, url: url, options: nil)
 
  } catch {
 
   // report any error we got.
 
   var dict = [string: anyobject]()
 
   dict[nslocalizeddescriptionkey] = "failed to initialize the application's saved data"
 
   dict[nslocalizedfailurereasonerrorkey] = failurereason
 
   
 
   dict[nsunderlyingerrorkey] = error as nserror
 
   let wrappederror = nserror(domain: "your_error_domain", code: 9999, userinfo: dict)
 
   // replace this with code to handle the error appropriately.
 
   // abort() causes the application to generate a crash log and terminate. you should not use this function in a shipping application, although it may be useful during development.
 
   nslog("unresolved error \(wrappederror), \(wrappederror.userinfo)")
 
   abort()
 
  }
 
  
 
  return coordinator
 
 }()
 
 
 
 lazy var managedobjectcontext: nsmanagedobjectcontext = {
 
  // returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) this property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
 
  let coordinator = self.persistentstorecoordinator
 
  var managedobjectcontext = nsmanagedobjectcontext(concurrencytype: .mainqueueconcurrencytype)
 
  managedobjectcontext.persistentstorecoordinator = coordinator
 
  return managedobjectcontext
 
 }()
 
 
 
 // mark: - core data saving support
 
 
 
 func savecontext () {
 
  if managedobjectcontext.haschanges {
 
   do {
 
    try managedobjectcontext.save()
 
   } catch {
 
    // replace this implementation with code to handle the error appropriately.
 
    // abort() causes the application to generate a crash log and terminate. you should not use this function in a shipping application, although it may be useful during development.
 
    let nserror = error as nserror
 
    nslog("unresolved error \(nserror), \(nserror.userinfo)")
 
    abort()
 
   }
 
  }
 
 }
 
 
 
}

2.appdelegate.swift 

在這個(gè)行數(shù)中加入一句代碼,退出后執(zhí)行保存一下

?
1
2
3
4
5
6
func applicationwillterminate(application: uiapplication) {
  // called when the application is about to terminate. save data if appropriate. see also applicationdidenterbackground:.
  // saves changes in the application's managed object context before the application terminates.
  xpstoremanager.shareinstance.savecontext()
 
 }

3.student.swift 

編寫了針對(duì)這個(gè)學(xué)生對(duì)象的增刪改查 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
//
 
// student.swift
 
// coredatademo
 
//
 
// created by cdmac on 16/9/12.
 
// copyright © 2016年 xiaopin.cnblogs.com. all rights reserved.
 
//
 
 
 
import foundation
 
import coredata
 
 
 
class student: nsmanagedobject {
 
 // insert code here to add functionality to your managed object subclass
 
 /*
 
  一般涉及到的情況有:增刪改,單對(duì)象查詢,分頁(yè)查詢(所有,條件查詢,排序),對(duì)象是否存在,批量增加,批量修改
 
  */
 
 
 
 /// 判斷對(duì)象是否存在, obj參數(shù)是當(dāng)前屬性的字典
 
 class func exsitsobject(obj:[string:string]) -> bool {
 
  
 
  //獲取管理數(shù)據(jù)對(duì)象的上下文
 
  let context = xpstoremanager.shareinstance.managedobjectcontext
 
  //聲明一個(gè)數(shù)據(jù)請(qǐng)求
 
  let fetchrequest = nsfetchrequest(entityname: "student")
 
  
 
  //組合過(guò)濾參數(shù)
 
  let stuid = obj["stuid"]
 
  let name = obj["name"]
 
  
 
  //方式一
 
  let predicate1 = nspredicate(format: "stuid = %@", stuid!)
 
  let predicate2 = nspredicate(format: "name = %@", name!)
 
  //合成過(guò)濾條件
 
  //or ,and, not , 意思是:或與非,懂?dāng)?shù)據(jù)庫(kù)的同學(xué)應(yīng)該就很容易明白
 
  let predicate = nscompoundpredicate(orpredicatewithsubpredicates: [predicate1,predicate2])
 
  //let predicate = nscompoundpredicate(andpredicatewithsubpredicates: [predicate1,predicate2])
 
  fetchrequest.predicate = predicate
 
  
 
  //方式二
 
  //fetchrequest.predicate = nspredicate(format: "stuid = %@ or name = %@", stuid!, name!)
 
  //fetchrequest.predicate = nspredicate(format: "stuid = %@ and name = %@", stuid!, name!)
 
  
 
  do{
 
   let fetchobjects:[anyobject]? = try context.executefetchrequest(fetchrequest)
 
   
 
   return fetchobjects?.count > 0 ? true : false
 
  }catch {
 
   fatalerror("exsitsobject \(error)")
 
  }
 
  
 
  return false
 
 }
 
 
 
 /// 添加對(duì)象, obj參數(shù)是當(dāng)前屬性的字典
 
 class func insertobject(obj: [string:string]) -> bool {
 
  
 
  //如果存在對(duì)象了就返回
 
  if exsitsobject(obj) {
 
   return false
 
  }
 
  
 
  //獲取管理的數(shù)據(jù)上下文 對(duì)象
 
  let context = xpstoremanager.shareinstance.managedobjectcontext
 
  
 
  //創(chuàng)建學(xué)生對(duì)象
 
  let stu = nsentitydescription.insertnewobjectforentityforname("student",
 
                  inmanagedobjectcontext: context) as! student
 
 
 
  //對(duì)象賦值
 
  let sexstr:string
 
  if obj["sex"] == "男"{
 
   sexstr = "1"
 
  }else{
 
   sexstr = "0"
 
  }
 
  let numberfmt = nsnumberformatter()
 
  numberfmt.numberstyle = .nostyle
 
  stu.stuid = numberfmt.numberfromstring(obj["stuid"]!)
 
  stu.name = obj["name"]
 
  stu.createtime = nsdate()
 
  stu.sex = numberfmt.numberfromstring(sexstr)
 
  stu.classid = numberfmt.numberfromstring(obj["classid"]!)
 
  
 
  //保存
 
  do {
 
   try context.save()
 
   print("保存成功!")
 
   return true
 
  } catch {
 
   fatalerror("不能保存:\(error)")
 
  }
 
  return false
 
 }
 
 
 
 /// 刪除對(duì)象
 
 class func deleteobject(obj:student) -> bool{
 
  
 
  //獲取管理的數(shù)據(jù)上下文 對(duì)象
 
  let context = xpstoremanager.shareinstance.managedobjectcontext
 
  
 
  //方式一: 比如說(shuō)列表已經(jīng)是從數(shù)據(jù)庫(kù)中獲取的對(duì)象,直接調(diào)用coredata默認(rèn)的刪除方法
 
  context.deleteobject(obj)
 
  xpstoremanager.shareinstance.savecontext()
 
  
 
  //方式二:通過(guò)obj參數(shù)比如:id,name ,通過(guò)這樣的條件去查詢一個(gè)對(duì)象一個(gè),把這個(gè)對(duì)象從數(shù)據(jù)庫(kù)中刪除
 
  //代碼:略
 
  
 
  return true
 
 }
 
 
 
 /// 更新對(duì)象
 
 class func updateobject(obj:[string: string]) -> bool {
 
  //obj參數(shù)說(shuō)明:當(dāng)前對(duì)象的要更新的字段信息,唯一標(biāo)志是必須的,其他的是可選屬性
 
  let context = xpstoremanager.shareinstance.managedobjectcontext
 
  
 
  let oid = obj["stuid"]
 
  let student:student = self.fetchobjectbyid(int(oid!)!)! as! student
 
  
 
  //遍歷參數(shù),然后替換相應(yīng)的參數(shù)
 
  let numberfmt = nsnumberformatter()
 
  numberfmt.numberstyle = .nostyle
 
  
 
  for key in obj.keys {
 
   switch key {
 
   case "name":
 
    student.name = obj["name"]
 
   case "classid":
 
    student.classid = numberfmt.numberfromstring(obj["classid"]!)
 
   default:
 
    print("如果有其他參數(shù)需要修改,類似")
 
   }
 
  }
 
  
 
  //執(zhí)行更新操作
 
  do {
 
   try context.save()
 
   print("更新成功!")
 
   return true
 
  } catch {
 
   fatalerror("不能保存:\(error)")
 
  }
 
  
 
  return false
 
 }
 
 
 
  /// 查詢對(duì)象
 
 class func fetchobjects(pageindex:int, pagesize:int) -> [anyobject]? {
 
  //獲取管理的數(shù)據(jù)上下文 對(duì)象
 
  let context = xpstoremanager.shareinstance.managedobjectcontext
 
  
 
  //聲明數(shù)據(jù)的請(qǐng)求
 
  let fetchrequest:nsfetchrequest = nsfetchrequest(entityname: "student")
 
  fetchrequest.fetchlimit = pagesize //每頁(yè)大小
 
  fetchrequest.fetchoffset = pageindex * pagesize //第幾頁(yè)
 
  
 
  //設(shè)置查詢條件:參考exsitsobject
 
  //let predicate = nspredicate(format: "id= '1' ", "")
 
  //fetchrequest.predicate = predicate
 
  
 
  //設(shè)置排序
 
  //按學(xué)生id降序
 
  let stuidsort = nssortdescriptor(key: "stuid", ascending: false)
 
  //按照姓名升序
 
  let namesort = nssortdescriptor(key: "name", ascending: true)
 
  let sortdescriptors:[nssortdescriptor] = [stuidsort,namesort]
 
  fetchrequest.sortdescriptors = sortdescriptors
 
  
 
  //查詢操作
 
  do {
 
   let fetchedobjects:[anyobject]? = try context.executefetchrequest(fetchrequest)
 
   
 
   //遍歷查詢的結(jié)果
 
   /*
 
   for info:student in fetchedobjects as! [student]{
 
    print("id=\(info.stuid)")
 
    print("name=\(info.name)")
 
    print("sex=\(info.sex)")
 
    print("classid=\(info.classid)")
 
    print("createtime=\(info.createtime)")
 
    print("-------------------")
 
    
 
   }
 
    */
 
   return fetchedobjects
 
  }
 
  catch {
 
   fatalerror("不能保存:\(error)")
 
  }
 
  return nil
 
 }
 
 
 
  /// 根據(jù)id查詢當(dāng)個(gè)對(duì)象
 
 class func fetchobjectbyid(oid:int) -> anyobject?{
 
  
 
  //獲取上下文對(duì)象
 
  let context = xpstoremanager.shareinstance.managedobjectcontext
 
  
 
  //創(chuàng)建查詢對(duì)象
 
  let fetchrequest:nsfetchrequest = nsfetchrequest(entityname: "student")
 
  
 
  //構(gòu)造參數(shù)
 
  fetchrequest.predicate = nspredicate(format: "stuid = %@", string(oid))
 
  
 
  //執(zhí)行代碼并返回結(jié)果
 
  do{
 
   let results:[anyobject]? = try context.executefetchrequest(fetchrequest)
 
   
 
   if results?.count > 0 {
 
    return results![0]
 
   }
 
  }catch{
 
   fatalerror("查詢當(dāng)個(gè)對(duì)象致命錯(cuò)誤:\(error)")
 
  }
 
  
 
  return nil
 
 }
 
}

4.viewcontroller.swift 

具體使用: 

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
//
 
// viewcontroller.swift
 
// coredatademo
 
//
 
// created by cdmac on 16/9/11.
 
// copyright © 2016年 pinguo. all rights reserved.
 
//
 
 
 
import uikit
 
 
 
let cellidentifiler = "reusecell"
 
 
 
class viewcontroller: uiviewcontroller {
 
 @iboutlet weak var txtno: uitextfield!
 
 @iboutlet weak var txtname: uitextfield!
 
 @iboutlet weak var txtsex: uitextfield!
 
 @iboutlet weak var txtclassid: uitextfield!
 
 @iboutlet weak var tableview: uitableview!
 
 var dataarray:[anyobject]?
 
 
 
 override func viewdidload() {
 
  super.viewdidload()
 
  // do any additional setup after loading the view, typically from a nib.
 
  self.dataarray = student.fetchobjects(0, pagesize: 20)
 
  self.tableview.reloaddata()
 
 }
 
 
 
 override func didreceivememorywarning() {
 
  super.didreceivememorywarning()
 
  // dispose of any resources that can be recreated.
 
 }
 
 
 
 
 
 @ibaction func addaction(sender: anyobject) {
 
 
 
  var dic = [string:string]()
 
  
 
  dic["stuid"] = txtno.text
 
  dic["name"] = txtname.text
 
  dic["sex"] = txtsex.text
 
  dic["classid"] = txtclassid.text
 
  
 
  if student.insertobject(dic) {
 
   print("添加成功")
 
   self.dataarray = student.fetchobjects(0,pagesize: 20)
 
   
 
   self.tableview.reloaddata()
 
  }else{
 
   print("添加失敗")
 
  }
 
 }
 
 
 
 @ibaction func updateaction(sender: anyobject) {
 
  
 
  var dic = [string:string]()
 
  
 
  dic["stuid"] = txtno.text
 
  dic["name"] = txtname.text
 
  //dic["sex"] = txtsex.text
 
  dic["classid"] = txtclassid.text
 
  
 
  if student.updateobject(dic) {
 
   print("更新成功")
 
   self.dataarray = student.fetchobjects(0,pagesize: 20)
 
   
 
   self.tableview.reloaddata()
 
  }else{
 
   print("更新失敗")
 
  }
 
  
 
 }
 
 
 
}
 
 
 
extension viewcontroller:uitableviewdelegate,uitableviewdatasource{
 
 
 
 //表格有多少組
 
 func numberofsectionsintableview(tableview: uitableview) -> int {
 
  return 1
 
 }
 
 
 
 //每組多少行
 
 func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {
 
  if self.dataarray != nil && self.dataarray?.count > 0 {
 
   return self.dataarray!.count
 
  }
 
  return 0
 
 }
 
 
 
 //高度
 
 func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat {
 
  return 50
 
 }
 
 
 
 //單元格加載
 
 func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {
 
  let cell = tableview.dequeuereusablecellwithidentifier(cellidentifiler)
 
  
 
  let stu:student = self.dataarray![indexpath.row] as! student
 
  
 
  let label1:uilabel = cell?.contentview.viewwithtag(10001) as! uilabel
 
  let label2:uilabel = cell?.contentview.viewwithtag(10002) as! uilabel
 
  var sexstr = "男"
 
  if stu.sex?.intvalue != 1 {
 
   sexstr = "女"
 
  }
 
  label1.text = "\(stu.stuid!) \(stu.name!) \(sexstr) \(stu.classid!)"
 
  label2.text = "http://xiaopin.cnblogs.com"
 
  
 
  return cell!
 
 }
 
 
 
 //選中
 
 func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {
 
  
 
 }
 
 
 
 func tableview(tableview: uitableview, caneditrowatindexpath indexpath: nsindexpath) -> bool {
 
  return true
 
 }
 
 
 
 func tableview(tableview: uitableview, commiteditingstyle editingstyle: uitableviewcelleditingstyle, forrowatindexpath indexpath: nsindexpath) {
 
  if editingstyle == .delete {
 
   //獲取當(dāng)前對(duì)象
 
   let student:student = self.dataarray![indexpath.row] as! student
 
   
 
   //刪除本地存儲(chǔ)
 
   student.deleteobject(student)
 
   
 
   //刷新數(shù)據(jù)源
 
   self.dataarray?.removeatindex(indexpath.row)
 
   //self.dataarray = student.fetchobjects(0, pagesize: 20)
 
   
 
   //刪除單元格
 
   tableview.deleterowsatindexpaths([indexpath], withrowanimation: .automatic)
 
  }
 
 }
 
 
 
 func tableview(tableview: uitableview, editingstyleforrowatindexpath indexpath: nsindexpath) -> uitableviewcelleditingstyle {
 
  return .delete
 
 }
 
 
 
 func tableview(tableview: uitableview, titlefordeleteconfirmationbuttonforrowatindexpath indexpath: nsindexpath) -> string? {
 
  return "刪除"
 
 }
 
}

運(yùn)行效果圖

iOS CoreData 增刪改查詳解

源碼下載:coredatademo.zip

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://www.cnblogs.com/xiaopin/archive/2016/09/18/5883203.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 国产精品一区二区av | 成人午夜性成交 | 久久精彩视频 | 久久99精品国产麻豆婷婷洗澡 | 黑人中文字幕一区二区三区 | 亚洲激情欧美 | 亚洲一二三 | 91精品久久久久久 | 日韩成人精品 | 日本手机在线视频 | 日韩欧美在线免费观看 | 毛片在线一区二区观看精品 | 亚洲综合在线视频 | 99re在线播放视频 | 日韩成人在线视频 | 成人国产在线 | www.99| 国产成人精品免费 | 久久艹色| 精品国产欧美一区二区三区成人 | 天天爱天天草 | 色就是色网站 | 一呦二呦三呦国产精品 | 成人精品鲁一区一区二区 | 视频一区二区三区中文字幕 | 国产成人精品一区二区三区四区 | 欧美麻豆视频 | 成人午夜毛片 | 一区二区三区视频在线观看 | 国产精品国产 | 国产免费啪 | 一区二区三区高清不卡 | 精品护士一区二区三区 | 精品国产欧美一区二区三区成人 | 天天射天天干 | 亚洲日本乱码一区两区在线观看 | 国外精品久久久蜜桃免费全文阅读 | 黄色片小视频 | 天天色天天色 | 欧美成人区 | 亚洲免费看av |