9
9
import UIKit
10
10
11
11
12
- class YTKKeyValueItem_Swift : NSObject {
12
+ public class YTKKeyValueItem_Swift : NSObject {
13
13
var itemId : String ?
14
14
var itemObject : AnyObject ?
15
15
var createdTime : NSDate ?
@@ -20,23 +20,22 @@ class YTKKeyValueItem_Swift:NSObject{
20
20
21
21
}
22
22
23
-
24
- class YTKKeyValueStore_Swift : NSObject {
23
+ public class YTKKeyValueStore_Swift : NSObject {
25
24
26
25
//文件夹路径
27
- let PATH_OF_DOCUMENT : String = NSSearchPathForDirectoriesInDomains ( . DocumentDirectory, . UserDomainMask, true ) [ 0 ] as String
26
+ private let PATH_OF_DOCUMENT : String = NSSearchPathForDirectoriesInDomains ( . DocumentDirectory, . UserDomainMask, true ) [ 0 ] as String
28
27
29
28
private var dbQueue : FMDatabaseQueue ?
30
29
31
- let DEFAULT_DB_NAME = " database_swift.sqlite "
32
- let CREATE_TABLE_SQL = " CREATE TABLE IF NOT EXISTS %@ ( id TEXT NOT NULL, json TEXT NOT NULL, createdTime TEXT NOT NULL, PRIMARY KEY(id)) "
33
- let UPDATE_ITEM_SQL = " REPLACE INTO %@ (id, json, createdTime) values (?, ?, ?) "
34
- let QUERY_ITEM_SQL = " SELECT json, createdTime from %@ where id = ? Limit 1 "
35
- let SELECT_ALL_SQL = " SELECT * from %@ "
36
- let CLEAR_ALL_SQL = " DELETE from %@ "
37
- let DELETE_ITEM_SQL = " DELETE from %@ where id = ? "
38
- let DELETE_ITEMS_SQL = " DELETE from %@ where id in ( %@ ) "
39
- let DELETE_ITEMS_WITH_PREFIX_SQL = " DELETE from %@ where id like ? "
30
+ private let DEFAULT_DB_NAME = " database_swift.sqlite "
31
+ private let CREATE_TABLE_SQL = " CREATE TABLE IF NOT EXISTS %@ ( id TEXT NOT NULL, json TEXT NOT NULL, createdTime TEXT NOT NULL, PRIMARY KEY(id)) "
32
+ private let UPDATE_ITEM_SQL = " REPLACE INTO %@ (id, json, createdTime) values (?, ?, ?) "
33
+ private let QUERY_ITEM_SQL = " SELECT json, createdTime from %@ where id = ? Limit 1 "
34
+ private let SELECT_ALL_SQL = " SELECT * from %@ "
35
+ private let CLEAR_ALL_SQL = " DELETE from %@ "
36
+ private let DELETE_ITEM_SQL = " DELETE from %@ where id = ? "
37
+ private let DELETE_ITEMS_SQL = " DELETE from %@ where id in ( %@ ) "
38
+ private let DELETE_ITEMS_WITH_PREFIX_SQL = " DELETE from %@ where id like ? "
40
39
41
40
42
41
/**
@@ -46,7 +45,7 @@ class YTKKeyValueStore_Swift: NSObject {
46
45
47
46
:returns: 合法性
48
47
*/
49
- class func checkTableName( tableName : String ! ) -> Bool {
48
+ private class func checkTableName( tableName : String ! ) -> Bool {
50
49
if find ( tableName, " " ) != nil {
51
50
println ( " error, table name: \( tableName) format error " )
52
51
return false
@@ -82,7 +81,7 @@ class YTKKeyValueStore_Swift: NSObject {
82
81
83
82
:param: tableName 表单名
84
83
*/
85
- func createTable( #tableName: String! ) {
84
+ public func createTable( #tableName: String! ) {
86
85
if !YTKKeyValueStore_Swift. checkTableName ( tableName) {
87
86
return
88
87
}
@@ -101,7 +100,7 @@ class YTKKeyValueStore_Swift: NSObject {
101
100
102
101
:param: tableName 表单名
103
102
*/
104
- func clearTable( #tableName: String! ) {
103
+ public func clearTable( #tableName: String! ) {
105
104
if !YTKKeyValueStore_Swift. checkTableName ( tableName) {
106
105
return
107
106
}
@@ -115,14 +114,16 @@ class YTKKeyValueStore_Swift: NSObject {
115
114
}
116
115
}
117
116
117
+ //MARK: 对象
118
+
118
119
/**
119
120
加入数据
120
121
121
122
:param: object 数据
122
123
:param: objectId 数据索引
123
124
:param: tableName 表单名
124
125
*/
125
- func putObject( object : AnyObject ! , withId objectId: String ! , intoTable tableName: String ! ) {
126
+ public func putObject( object : AnyObject ! , withId objectId: String ! , intoTable tableName: String ! ) {
126
127
if !YTKKeyValueStore_Swift. checkTableName ( tableName) {
127
128
return
128
129
}
@@ -151,7 +152,7 @@ class YTKKeyValueStore_Swift: NSObject {
151
152
152
153
:returns: 对象数据
153
154
*/
154
- func getObjectById( objectId : String ! , fromTable tableName : String ! ) -> AnyObject ? {
155
+ public func getObjectById( objectId : String ! , fromTable tableName : String ! ) -> AnyObject ? {
155
156
let item = self . getYTKKeyValueItemById ( objectId, fromTable: tableName)
156
157
if item != nil {
157
158
return item!. itemObject
@@ -167,7 +168,7 @@ class YTKKeyValueStore_Swift: NSObject {
167
168
168
169
:returns: 对象数据
169
170
*/
170
- func getYTKKeyValueItemById( objectId : String ! , fromTable tableName : String ! ) -> YTKKeyValueItem_Swift ? {
171
+ public func getYTKKeyValueItemById( objectId : String ! , fromTable tableName : String ! ) -> YTKKeyValueItem_Swift ? {
171
172
if !YTKKeyValueStore_Swift. checkTableName ( tableName) {
172
173
return nil
173
174
}
@@ -199,6 +200,7 @@ class YTKKeyValueStore_Swift: NSObject {
199
200
}
200
201
}
201
202
203
+ //MARK: 字符串
202
204
203
205
/**
204
206
插入字符串
@@ -207,7 +209,7 @@ class YTKKeyValueStore_Swift: NSObject {
207
209
:param: stringId 索引
208
210
:param: tableName 表单名
209
211
*/
210
- func putString( string : String ! , withId stringId : String ! , intoTable tableName: String ! ) {
212
+ public func putString( string : String ! , withId stringId : String ! , intoTable tableName: String ! ) {
211
213
self . putObject ( [ string] , withId: stringId, intoTable: tableName)
212
214
}
213
215
@@ -219,7 +221,7 @@ class YTKKeyValueStore_Swift: NSObject {
219
221
220
222
:returns: 字符串
221
223
*/
222
- func getStringById( stringId : String ! , fromTable tableName : String ! ) -> String ? {
224
+ public func getStringById( stringId : String ! , fromTable tableName : String ! ) -> String ? {
223
225
let array : AnyObject ? = self . getObjectById ( stringId, fromTable: tableName)
224
226
if let result = array as? [ String ] {
225
227
return result [ 0 ]
@@ -228,14 +230,16 @@ class YTKKeyValueStore_Swift: NSObject {
228
230
}
229
231
}
230
232
233
+ //MARK: 数组
234
+
231
235
/**
232
236
插入数字
233
237
234
238
:param: number 数字
235
239
:param: numberId 索引
236
240
:param: tableName 表单名
237
241
*/
238
- func putNumber( number : CGFloat ! , withId numberId : String ! , intoTable tableName : String ! ) {
242
+ public func putNumber( number : CGFloat ! , withId numberId : String ! , intoTable tableName : String ! ) {
239
243
self . putObject ( [ number] , withId: numberId, intoTable: tableName)
240
244
}
241
245
@@ -247,7 +251,7 @@ class YTKKeyValueStore_Swift: NSObject {
247
251
248
252
:returns: 数字
249
253
*/
250
- func getNumberById( numberId : String ! , fromTable tableName : String ! ) -> CGFloat ? {
254
+ public func getNumberById( numberId : String ! , fromTable tableName : String ! ) -> CGFloat ? {
251
255
let array : AnyObject ? = self . getObjectById ( numberId, fromTable: tableName)
252
256
if let result = array as? [ CGFloat ] {
253
257
return result [ 0 ]
@@ -256,14 +260,16 @@ class YTKKeyValueStore_Swift: NSObject {
256
260
}
257
261
}
258
262
263
+ //MARK: 其他
264
+
259
265
/**
260
266
获取表单的所有的数据
261
267
262
268
:param: tableName 表单名
263
269
264
270
:returns: 所有数据
265
271
*/
266
- func getAllItemsFromTable( tableName : String ! ) -> [ AnyObject ] ? {
272
+ public func getAllItemsFromTable( tableName : String ! ) -> [ AnyObject ] ? {
267
273
if !YTKKeyValueStore_Swift. checkTableName ( tableName) {
268
274
return nil
269
275
}
@@ -298,12 +304,12 @@ class YTKKeyValueStore_Swift: NSObject {
298
304
}
299
305
300
306
/**
301
- 根据所以删除数据
307
+ 根据索引删除数据
302
308
303
309
:param: objectId 索引
304
310
:param: tableName 表单名
305
311
*/
306
- func deleteObjectById( objectId : String ! , fromTable tableName: String ! ) {
312
+ public func deleteObjectById( objectId : String ! , fromTable tableName: String ! ) {
307
313
if !YTKKeyValueStore_Swift. checkTableName ( tableName) {
308
314
return
309
315
}
@@ -323,7 +329,7 @@ class YTKKeyValueStore_Swift: NSObject {
323
329
:param: objectIdArray 索引数组
324
330
:param: tableName 表单名
325
331
*/
326
- func deleteObjectsByIdArray( objectIdArray: [ AnyObject ] ! , fromTable tableName : String ! ) {
332
+ public func deleteObjectsByIdArray( objectIdArray: [ AnyObject ] ! , fromTable tableName : String ! ) {
327
333
if !YTKKeyValueStore_Swift. checkTableName ( tableName) {
328
334
return
329
335
}
@@ -352,7 +358,7 @@ class YTKKeyValueStore_Swift: NSObject {
352
358
:param: objectIdPrefix 索引前缀
353
359
:param: tableName 表单名
354
360
*/
355
- func deleteObjectsByIdPrefix( objectIdPrefix : String , fromTable tableName: String ) {
361
+ public func deleteObjectsByIdPrefix( objectIdPrefix : String , fromTable tableName: String ) {
356
362
if !YTKKeyValueStore_Swift. checkTableName ( tableName) {
357
363
return
358
364
}
@@ -370,7 +376,7 @@ class YTKKeyValueStore_Swift: NSObject {
370
376
/**
371
377
关闭数据库
372
378
*/
373
- func close( ) {
379
+ public func close( ) {
374
380
dbQueue? . close ( )
375
381
dbQueue = nil
376
382
}
0 commit comments