From 110a8e28a8c4bfa488bfdea0566224fd7c71ae47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 8 Sep 2015 22:33:28 +0200 Subject: [PATCH] Documentation --- GRDB/Core/DatabaseValue.swift | 3 ++- GRDB/Core/Row.swift | 6 ++++-- GRDB/RowModel/RowModel.swift | 6 +++--- README.md | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index 105820bf3..f52eeab7a 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -67,10 +67,11 @@ public enum DatabaseValue : Equatable { let value: Double? = databaseValue.value() **WARNING**: type casting requires a very careful use of the `as` operator - (see [rdar://problem/21676393](http://openradar.appspot.com/radar?id=4951414862249984)): + (see [rdar://21676393](http://openradar.appspot.com/radar?id=4951414862249984)): databaseValue.value()! as Int // OK: Int databaseValue.value() as Int? // OK: Int? + databaseValue.value() as! Int // NO NO NO DON'T DO THAT! databaseValue.value() as? Int // NO NO NO DON'T DO THAT! Your custom types that adopt the DatabaseValueConvertible protocol handle diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 641d2d315..7ad4b006a 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -63,11 +63,12 @@ public struct Row: CollectionType { let value: Double? = row.value(atIndex: 0) **WARNING**: type casting requires a very careful use of the `as` operator - (see [rdar://problem/21676393](http://openradar.appspot.com/radar?id=4951414862249984)): + (see [rdar://21676393](http://openradar.appspot.com/radar?id=4951414862249984)): row.value(atIndex: 0)! as Int // OK: Int row.value(atIndex: 0) as Int? // OK: Int? row.value(atIndex: 0) as? Int // NO NO NO DON'T DO THAT! + row.value(atIndex: 0) as! Int // NO NO NO DON'T DO THAT! Your custom types that adopt the DatabaseValueConvertible protocol handle their own conversion from raw SQLite values. Yet, here is the reference for @@ -127,10 +128,11 @@ public struct Row: CollectionType { let value: Double? = row.value(named: "count") **WARNING**: type casting requires a very careful use of the `as` operator - (see [rdar://problem/21676393](http://openradar.appspot.com/radar?id=4951414862249984)): + (see [rdar://21676393](http://openradar.appspot.com/radar?id=4951414862249984)): row.value(named: "count")! as Int // OK: Int row.value(named: "count") as Int? // OK: Int? + row.value(named: "count") as! Int // NO NO NO DON'T DO THAT! row.value(named: "count") as? Int // NO NO NO DON'T DO THAT! Your custom types that adopt the DatabaseValueConvertible protocol handle diff --git a/GRDB/RowModel/RowModel.swift b/GRDB/RowModel/RowModel.swift index d0a4d1d00..7f8f35dac 100644 --- a/GRDB/RowModel/RowModel.swift +++ b/GRDB/RowModel/RowModel.swift @@ -248,9 +248,9 @@ public class RowModel : RowConvertible, DatabaseTableMapping, DatabaseStorable { } else { // No statement means that there is no column to update. // - // I remember opening rdar://problem/10236982 because CoreData - // was crashing with entities without any attribute. So let's - // accept RowModel that don't have any column to update. + // I remember opening rdar://10236982 because CoreData was crashing + // with entities without any attribute. So let's accept RowModel + // that don't have any column to update. exists = self.exists(db) } diff --git a/README.md b/README.md index cb8a1c545..860a548b9 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ let bookCount64: Int64 = row.value(named: "bookCount")! let hasBooks: Bool = row.value(named: "bookCount")! // false when 0 ``` -**WARNING**: type casting requires a very careful use of the `as` operator (see [rdar://problem/21676393](http://openradar.appspot.com/radar?id=4951414862249984)): +**WARNING**: type casting requires a very careful use of the `as` operator (see [rdar://21676393](http://openradar.appspot.com/radar?id=4951414862249984)): ```swift row.value(named: "bookCount")! as Int // OK: Int @@ -561,7 +561,7 @@ All types that adopt this protocol can be used wherever the built-in types `Int` The `databaseValue` property returns [DatabaseValue](GRDB/Core/DatabaseValue.swift), an enum for the five types supported by SQLite: NULL, integer, real, string and blob. -The `fromDatabaseValue()` factory method returns an instance of your custom type if the databaseValue contains a suitable value. +The `fromDatabaseValue()` factory method returns an instance of your custom type, if the databaseValue contains a suitable value. As an example, let's write an alternative to the built-in [NSDate](#nsdate-and-nsdatecomponents) behavior, and store dates as timestamps. Our sample DatabaseTimestamp type applies all the best practices for a great GRDB.swift integration: