Skip to content

Commit

Permalink
Improves the type detection algorithm for DataTableValueType enum
Browse files Browse the repository at this point in the history
  • Loading branch information
pavankataria committed Mar 13, 2017
1 parent f3d9d2c commit b0254e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Example/SwiftDataTables/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public func exampleDataSet() -> [[Any]] {
[1,"Meggie Block","[email protected]","(397) 102-5456 x371","Emilioshire","876.06"],
[2,"Waldo Sporer","[email protected]","(726) 447-9616 x726","Port Jedediahfurt","220.69"],
[3,"Vickie Stroman","[email protected]","1-347-447-3401 x491","Delbertberg","340.64"],
[4,"Kiley Denesik","[email protected]","069.128.7032","South Aidaside","271.01"],
[[4,"Kiley Denesik","[email protected]","069.128.7032","South Aidaside","271.01"],
[5,"Shanie Langworth","[email protected]","185-323-3421","Ileneville","342.04"],
[6,"Clifford Greenfelder","[email protected]","1-445-170-5544 x69505","Zboncakburgh","660.10"],
[7,"Lurline Rolfson","[email protected]","1-839-002-7378 x36811","New Mitchelshire","401.82"],
Expand Down
29 changes: 20 additions & 9 deletions SwiftDataTables/Classes/DataTableValueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,29 @@ public enum DataTableValueType {
}
}

public init?(_ value: Any){
if let value = value as? Int {
public init(_ value: Any){
//Determine the actual type first
switch value {
case let value as Int:
self = .int(value)
}
else if let value = value as? Float {
case let value as Float:
self = .float(value)
}
else if let value = value as? Double {
case let value as Double:
self = .double(value)
}
else {
self = .string(String(describing: value))
default:
let temporaryStringRepresentation = String(describing: value)
if let value = Int(temporaryStringRepresentation) {
self = .int(value)
}
else if let value = Float(temporaryStringRepresentation) {
self = .float(value)
}
else if let value = Double(temporaryStringRepresentation) {
self = .double(value)
}
else {
self = .string(temporaryStringRepresentation)
}
}
}
}
Expand Down

0 comments on commit b0254e8

Please sign in to comment.