From a8a3ec8259e4f3875ea299dcba0067f38fcbd270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 25 Aug 2018 15:31:59 +0200 Subject: [PATCH] Enhance Swift Enums documentation --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 72c38d2d4..df3e49cec 100644 --- a/README.md +++ b/README.md @@ -1369,7 +1369,7 @@ while let row = try rows.next() { } ``` -**When a database value does not match any enum case**, you get a fatal error. This fatal error can be avoided with the [DatabaseValueConvertible.fromDatabaseValue()](#custom-value-types) method: +**When a database value does not match any enum case**, you get a fatal error. This fatal error can be avoided with the [DatabaseValue](#databasevalue) type: ```swift let row = try Row.fetchOne(db, "SELECT 'syrah'")! @@ -1377,7 +1377,15 @@ let row = try Row.fetchOne(db, "SELECT 'syrah'")! row[0] as String // "syrah" row[0] as Grape? // fatal error: could not convert "syrah" to Grape. row[0] as Grape // fatal error: could not convert "syrah" to Grape. -Grape.fromDatabaseValue(row[0]) // nil + +let dbValue: DatabaseValue = row[0] +if dbValue.isNull { + // Handle NULL +} else if let grape = Grape.fromDatabaseValue(dbValue) { + // Handle valid grape +} else { + // Handle unknown grape +} ```