From e1e4dd05241fa06f2d4531bd18a50a19cb49c3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 1 Feb 2016 08:00:32 +0100 Subject: [PATCH] Documentation for RowConvertible.init(_:Row) --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f2c19e9e9..1402b24a6 100644 --- a/README.md +++ b/README.md @@ -1352,8 +1352,8 @@ You can now jump to: ```swift public protocol RowConvertible { - /// Returns a value initialized from `row`. - static func fromRow(row: Row) -> Self + /// Row initializer + init(_ row: Row) /// Optional method which gives adopting types an opportunity to complete /// their initialization after being fetched. Do not call it directly. @@ -1371,20 +1371,19 @@ struct PointOfInterest { } extension PointOfInterest : RowConvertible { - static func fromRow(row: Row) -> PointOfInterest { - return PointOfInterest( - id: row.value(named: "id"), - title: row.value(named: "title"), - coordinate: CLLocationCoordinate2DMake( - row.value(named: "latitude"), - row.value(named: "longitude"))) + init(_ row: Row){ + id = row.value(named: "id") + title = row.value(named: "title") + coordinate = CLLocationCoordinate2DMake( + row.value(named: "latitude"), + row.value(named: "longitude")) } } ``` See [Column Values](#column-values) for more information about the `row.value()` method. -> :point_up: **Note**: For performance reasons, the same row argument to `fromRow(:)` is reused during the iteration of a fetch query. If you want to keep the row for later use, make sure to store a copy: `self.row = row.copy()`. +> :point_up: **Note**: For performance reasons, the same row argument to `init(_:Row)` is reused during the iteration of a fetch query. If you want to keep the row for later use, make sure to store a copy: `self.row = row.copy()`. RowConvertible allows adopting types to be fetched from SQL queries: