Question
I need to post data into the firebase database, which (in terms of arrays) can only accept type NSArray. The application however, needs to add to the array
Json Data that wil be posted
Object: someObjectKey[
ArrayOfItems[
Item: someItemNumber
Item: someItemNumber
Item: someItemNumber
]
TimeStamp: 102047355
SomeOtherTimeStamp: null
SomeInt: 1111
someOtherInt: 2222
SomeBoolean: false
]
}
Goal
How can I get the data above to be pushed up into the database?
Attempted Avenues
-Convert a SwiftArray to a NSArray
-Convert an NSMutableArray to a NSArray
Code
public func postToFireBase(){
var Timestamp: String {
return "\(NSDate().timeIntervalSince1970 * 1000)"
}
var someInt = 1111
var someOtherInt = 2222
let myArrayOfStuff = convertItemsToNSArray()
let post: [String : Any] = ["timestamp": Timestamp,
"someInt": someInt,
"someOtherInt": someOtherInt,
"items": ItemList]
//Method Call References the FIRDatabase.database.reference.child...
FirebaseDatabaseService.databaseReference.setValue(post)
}
private func convertItemsToNSArray() -> NSArray{
var thisArray: NSMutableArray = []
for item in items{
thisArray.add(["name": "Foo",
"key": "Bar",
"someCoolInt": 1234])
}
return thisArray
//This won't work because it's coming back as NSMutableArray anyway
}
Cheers