Browse Source

Add Swift extension

Added extension for variadic renditions of `executeUpdate` and `executeQuery`.
Rob Ryan 11 years ago
parent
commit
298602b44a
1 changed files with 36 additions and 0 deletions
  1. 36 0
      src/extra/Swift extensions/FMDatabaseVariadic.swift

+ 36 - 0
src/extra/Swift extensions/FMDatabaseVariadic.swift

@@ -0,0 +1,36 @@
+//
+//  FMDatabaseVariadic.swift
+//  FMDB
+//
+
+
+//  This extension inspired by http://stackoverflow.com/a/24187932/1271826
+
+import Foundation
+
+extension FMDatabase {
+
+    /// This is a rendition of executeQuery that handles Swift variadic parameters
+    /// for the values to be bound to the ? placeholders in the SQL.
+    ///
+    /// :param: sql The SQL statement to be used.
+    /// :param: values The values to be bound to the ? placeholders
+    ///
+    /// :returns: This returns FMResultSet if successful. Returns nil upon error.
+
+    func executeQuery(sql:String, _ values: AnyObject...) -> FMResultSet? {
+        return executeQuery(sql, withArgumentsInArray: values as NSArray);
+    }
+
+    /// This is a rendition of executeUpdate that handles Swift variadic parameters
+    /// for the values to be bound to the ? placeholders in the SQL.
+    ///
+    /// :param: sql The SQL statement to be used.
+    /// :param: values The values to be bound to the ? placeholders
+    ///
+    /// :returns: This returns true if successful. Returns false upon error.
+
+    func executeUpdate(sql:String, _ values: AnyObject...) -> Bool {
+        return executeUpdate(sql, withArgumentsInArray: values as NSArray);
+    }
+}