I have a piece of code I've used in an objective c app that I want to incorporate into a new swift project. Problem is I can't work out the syntax!
I'm using FMDB to get some information about sets of cards from a sql database. When I pull the information out of the database I create a card object which has properties described in the database. When I access the database it returns an NSMutableArray
of my card objects. I want to explicitly state that my mutable array contains these objects...
I would do this in objective c by writing:
NSMutableArray<Card*>
I'm using it in this context
- (NSMutableArray<Card *> *)getCardsFromDb
So I know my function is returning a mutable array of Card
objects. How can I do this in swift?
at the moment the code in my project is minimal
//Properties
var cardArray: NSMutableArray<Card>! //How can I tell it that the array is populated with my Card object?
//View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
let databaseAccess = DatabaseAccess()
cardArray = databaseAccess.getCardsFromDatabase()
print(cardArray)
}
For the moment I've just called the array a temporary name because I was just testing that the database methods worked. I have tried NSMutableArray[Card]
and NSMutableArray(Card)
but neither worked.
I would like to do this so that I know when making the database call I am getting an array of card objects, not just some random array.
Thanks