resultset - How to handle resultDictionary nulls in swift? -


with fmdb resultset's resultdictionary method returns dictionary each row keys column names have value or nsnulls. trying figure out how best handle these , where.

so new update of swift need change code , in process looking @ refactoring.

so stands following line of code's "as" needs made "as?" or "as!" :

resultsarray.append(resultset.resultdictionary() dictionary<string,anyobject>) 

robert stated should handle them this. got me thinking better solution , looking advice on how should refactor:

  1. i optional, find nulls , replace nsnulls empty string literals "" , handle empty strings somewhere else in app.
  2. i leave them , force unwrap.

public class func querygetallrowsfromtableasarrayofhashes() -> array<dictionary<string,anyobject>>? {

var resultsarray = array<dictionary<string,anyobject>>() let database = dbutility.getdatabasehandle()  //perform query , place result dictionary. self.log().info("getting rows from: \(self.gettablename())") if let resultset = database.executequery(self.getallrowsstatement()) {     self.log().info("query run")     while resultset.next() {         //adds dictionary of result row array.         resultsarray.append(resultset.resultdictionary() as! dictionary<string,anyobject>)     }     self.log().info("results array: \(resultsarray)")     return resultsarray; }else{    self.log().error("db error: \(database.lasterrormessage())") } return nil; } 

anyone got advice on should tackled?

you can put check in if statement this

if var dict = resultset.resultdictionary() dictionary<string,anyobject>  {   resultsarray.append(resultset.resultdictionary() as! dictionary<string,anyobject>) } 

it append value in array if there non null value. hope you.if value null if statement not executed.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -