Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "TableViewController.h"
- #import "Car.h"
- #import "Vehicle.h"
- @interface TableViewController ()
- @end
- @implementation TableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Uncomment the following line to preserve selection between presentations.
- // self.clearsSelectionOnViewWillAppear = NO;
- // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
- // self.navigationItem.rightBarButtonItem = self.editButtonItem;
- self.db = [FIRFirestore firestore];
- self.myCars = [[NSMutableArray alloc] init];
- [[[[self.db collectionWithPath:@"users"] documentWithPath:[FIRAuth auth].currentUser.uid]
- collectionWithPath:@"cars"] getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
- if (error != nil) {
- NSLog(@"Error getting documents: %@", error);
- } else {
- for (FIRDocumentSnapshot *document in snapshot.documents) {
- NSLog(@"%@ => %@", document.documentID, document.data);
- Car *car = [[Car alloc] initWithCarName:[document valueForField:@"carname"] andCarStyle:[document valueForField:@"carstyle"]
- andCarColour:[document valueForField:@"colour"] andCarYear:[document valueForField:@"caryear"]
- andCarDoors:[document valueForField:@"doors"] andCarSeat:[document valueForField:@"seat"] andCarWheels:[document valueForField:@"wheels"]
- andCarTankCapacity:[document valueForField:@"tankcapacity"] andCarHorsePower:[document valueForField:@"horsepower"] andCarModelName:[document valueForField:@"modelname"]];
- NSLog(@"Car name:%@", car.name);
- [self.myCars addObject:car];
- }
- }
- }];
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.myCars count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellidentifier" forIndexPath:indexPath];
- // Configure the cell...'
- Vehicle *vehicle = [self.myCars objectAtIndex:indexPath.row];
- cell.textLabel.text = vehicle.name;
- return cell;
- }
- @end
Add Comment
Please, Sign In to add comment