Guest User

Untitled

a guest
Feb 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #import "TableViewController.h"
  2. #import "Car.h"
  3. #import "Vehicle.h"
  4.  
  5. @interface TableViewController ()
  6.  
  7. @end
  8.  
  9. @implementation TableViewController
  10.  
  11. - (void)viewDidLoad {
  12. [super viewDidLoad];
  13.  
  14. // Uncomment the following line to preserve selection between presentations.
  15. // self.clearsSelectionOnViewWillAppear = NO;
  16.  
  17. // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
  18. // self.navigationItem.rightBarButtonItem = self.editButtonItem;
  19.  
  20. self.db = [FIRFirestore firestore];
  21. self.myCars = [[NSMutableArray alloc] init];
  22.  
  23.  
  24. [[[[self.db collectionWithPath:@"users"] documentWithPath:[FIRAuth auth].currentUser.uid]
  25. collectionWithPath:@"cars"] getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
  26. if (error != nil) {
  27. NSLog(@"Error getting documents: %@", error);
  28. } else {
  29. for (FIRDocumentSnapshot *document in snapshot.documents) {
  30. NSLog(@"%@ => %@", document.documentID, document.data);
  31. Car *car = [[Car alloc] initWithCarName:[document valueForField:@"carname"] andCarStyle:[document valueForField:@"carstyle"]
  32. andCarColour:[document valueForField:@"colour"] andCarYear:[document valueForField:@"caryear"]
  33. andCarDoors:[document valueForField:@"doors"] andCarSeat:[document valueForField:@"seat"] andCarWheels:[document valueForField:@"wheels"]
  34. andCarTankCapacity:[document valueForField:@"tankcapacity"] andCarHorsePower:[document valueForField:@"horsepower"] andCarModelName:[document valueForField:@"modelname"]];
  35.  
  36. NSLog(@"Car name:%@", car.name);
  37.  
  38. [self.myCars addObject:car];
  39.  
  40. }
  41. }
  42. }];
  43.  
  44. }
  45.  
  46. #pragma mark - Table view data source
  47.  
  48. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  49. return 1;
  50. }
  51.  
  52. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  53. return [self.myCars count];
  54. }
  55.  
  56.  
  57. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  58. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellidentifier" forIndexPath:indexPath];
  59.  
  60. // Configure the cell...'
  61. Vehicle *vehicle = [self.myCars objectAtIndex:indexPath.row];
  62. cell.textLabel.text = vehicle.name;
  63.  
  64. return cell;
  65. }
  66.  
  67.  
  68.  
  69. @end
Add Comment
Please, Sign In to add comment