0

Im using the following code to invoke a method,

APIRequest *apiRequest = [[APIRequest alloc]init];
apiRequest.pendingShipmentDetails ;

Im getting the following warning,

property access result unused getters should not be used for side effects

what does it mean?

and the method is getting called twice at the same time

Following is my method,

-(void)pendingShipmentDetails
{
    keyChain = [[KeyChainItemWrapper alloc] initWithIdentifier:@"LoginController" accessGroup:nil];
    NSString *username = [keyChain objectForKey:(__bridge id)(kSecAttrLabel)];

    NSString *bodyString = [NSString stringWithFormat:@"{\"method\":\"pending_shipment_details\",\"data\":{\"username\":\"%@\"}}",username];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"url"]];
    NSData *postData = [bodyString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    [request setHTTPBody:postData];
    [request setHTTPMethod:@"POST"];
    NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];

    NSOperationQueue *queue = [[NSOperationQueue alloc] init];

    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
         if ([data length] > 0 && connectionError == nil)
         {
             [self receivedPendingShipmentDetailsData:data];
             NSString* pendingResponse = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
             NSData *jsonData = [pendingResponse dataUsingEncoding:NSUTF8StringEncoding];
             NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
             NSDictionary *valueDict = [jsonDic objectForKey:@"value"];

             NSArray *details = [valueDict objectForKey:@"details"];

             NSMutableArray* arrayList = [[NSMutableArray alloc] init];

             for (NSDictionary *response in details) {
                 NSString *invoiceNo = [response valueForKey:@"invoice_no"];
                 NSString *shipmentNumber = [response valueForKey:@"shipment_no"];
                 NSString *invoiceDate = [response valueForKey:@"invoice_date"];
                 NSString *proformaInvoiceNumber = [response valueForKey:@"proforma_invoice_no"];
                 NSString *proformaInvoiceDate = [response valueForKey:@"proforma_invoice_date"];
                 NSString *plannedShipmentDates = [response valueForKey:@"planned_shipment_dates"];
                 NSString *pointOfContact =[[response objectForKey:@"point_of_contact"] valueForKey:@"empid"];
                 NSString *pendingStatus = [response valueForKey:@"status"];
                 NSDictionary *productName = [response valueForKey:@"products"];
                 NSDictionary *quantity = [response valueForKey:@"quantity"];
                 NSDictionary *rate = [response valueForKey:@"rate"];
                 NSDictionary *amount = [response valueForKey:@"amount"];
                 NSDictionary *productImages = [response valueForKey:@"product_image"];
                 NSDictionary *point_of_contact = [response valueForKey:@"point_of_contact"];

                 NSString *qty;
                 NSString *rte;
                 NSString *img;
                 NSString *address;
                 NSString *name;
                 NSString *amt;

                 for (int i = 0; i < [productName count]; i++) {
                     //  NSLog(@"product name %@",[productName valueForKey:[NSString stringWithFormat:@"%d",i ]]);
                     name = [productName valueForKey:[NSString stringWithFormat:@"%d",i ]];
                 }

                 for (int i = 0; i < [quantity count]; i++) {
                     //  NSLog(@"quantity %@",[quantity valueForKey:[NSString stringWithFormat:@"%d",i ]]);
                     qty = [quantity valueForKey:[NSString stringWithFormat:@"%d",i ]];
                 }

                 for (int i = 0; i < [rate count]; i++) {
                     //  NSLog(@"rate %@",[rate valueForKey:[NSString stringWithFormat:@"%d",i ]]);
                     rte = [rate valueForKey:[NSString stringWithFormat:@"%d",i ]];
                 }

                 for (int i = 0; i < [amount count]; i++) {
                     // NSLog(@"amount %@",[amount valueForKey:[NSString stringWithFormat:@"%d",i ]]);
                     amt = [amount valueForKey:[NSString stringWithFormat:@"%d",i ]];
                 }


                 for (int i = 0; i < [productImages count]; i++) {
                     // NSLog(@"product image %@",[productImages valueForKey:[NSString stringWithFormat:@"%d",i ]]);
                     img = [productImages valueForKey:[NSString stringWithFormat:@"%d",i ]];
                 }

                 for (int i = 0; i < [point_of_contact count]; i++) {
                     //  NSLog(@"pt of ct %@",[point_of_contact valueForKey:[NSString stringWithFormat:@"empid" ]]);
                     address = [point_of_contact valueForKey:[NSString stringWithFormat:@"empid" ]];
                 }


                 NSManagedObjectContext *context = [self managedObjectContext];

                 //update
                 if((self.pendingShipmentDAO) ) {
                     NSLog(@"update");
                     [self.pendingShipmentDAO setValue:shipmentNumber forKey:@"shipmentno"];
                     [self.pendingShipmentDAO setValue:proformaInvoiceNumber forKey:@"proforma_invoice_no"];
                     [self.pendingShipmentDAO setValue:proformaInvoiceDate forKey:@"proforma_invoice_date"];
                     [self.pendingShipmentDAO setValue:invoiceNo forKey:@"invoice_no"];
                     [self.pendingShipmentDAO setValue:invoiceDate forKey:@"invoice_date"];
                     [self.pendingShipmentDAO setValue:plannedShipmentDates forKey:@"planned_shipment_date"];
                     [self.pendingShipmentDAO setValue:address forKey:@"point_of_contact"];
                     [self.pendingShipmentDAO setValue:address forKey:@"empid"];
                     [self.pendingShipmentDAO setValue:name forKey:@"products"];
                     [self.pendingShipmentDAO setValue:qty forKey:@"quantity"];
                     [self.pendingShipmentDAO setValue:rte forKey:@"rate"];
                     [self.pendingShipmentDAO setValue:amt forKey:@"amount"];
                     [self.pendingShipmentDAO setValue:img forKey:@"product_image"];
                     [self.pendingShipmentDAO setValue:pendingStatus forKey:@"status"];
                 }else {

                     NSLog(@"create");

                     NSManagedObject *pendingShipment = [NSEntityDescription insertNewObjectForEntityForName:@"PendingShipmentDetails" inManagedObjectContext:context];

                     // [self deleteAllPreviousData];
                     [pendingShipment setValue:shipmentNumber forKey:@"shipmentno"];
                     [pendingShipment setValue:proformaInvoiceNumber forKey:@"proforma_invoice_no"];
                     [pendingShipment setValue:proformaInvoiceDate forKey:@"proforma_invoice_date"];
                     [pendingShipment setValue:invoiceNo forKey:@"invoice_no"];
                     [pendingShipment setValue:invoiceDate forKey:@"invoice_date"];
                     [pendingShipment setValue:plannedShipmentDates forKey:@"planned_shipment_date"];
                     [pendingShipment setValue:address forKey:@"point_of_contact"];
                     [pendingShipment setValue:address forKey:@"empid"];
                     [pendingShipment setValue:name forKey:@"products"];
                     [pendingShipment setValue:qty forKey:@"quantity"];
                     [pendingShipment setValue:rte forKey:@"rate"];
                     [pendingShipment setValue:amt forKey:@"amount"];
                     [pendingShipment setValue:img forKey:@"product_image"];
                     [pendingShipment setValue:pendingStatus forKey:@"status"];


                 }
             }
         }

         else if ([data length] == 0 && connectionError == nil)
         {
             [self emptyReply];
         }
         else if (connectionError != nil && connectionError.code == NSURLErrorTimedOut)
         {
             [self timedOut];
         }
         else if (connectionError != nil)
         {
             [self downloadError:connectionError];
         }
     }];

}
  • Show the class *declaration* (the `@interface` bit); there must be a `@property SomeType *pendingShipmentDetails;` there somewhere... – trojanfoe Mar 23 '16 at 10:35
  • `@interface MyOrdersController () @property (strong) NSMutableArray *devices; @end ` –  Mar 23 '16 at 10:38

1 Answers1

0

Dot notation is used for properties (getting or setting) them. So here the compiler understands that you want to call the getter of pendingShipmentDetails which is not the case. You must use [] to call methods. Replace apiRequest.pendingShipmentDetails with [apiRequest pendingShipmentDetails] and the warning should disappear.

Jelly
  • 4,522
  • 6
  • 26
  • 42
  • that works. can you please help me to rectify the second error as well? –  Mar 23 '16 at 10:38
  • else loop is being executed twice –  Mar 23 '16 at 10:38
  • 1
    "you want to call the setter" do you mean `getter` maybe? – Luca D'Alberti Mar 23 '16 at 10:38
  • im actually parsing the json and adding those contents to an entity of core data. then, im creating a NSManagedObject instance, if no such instance exists previously. if it exists im trying to update the entities with newly fetched datas but it ain't happening. :( –  Mar 23 '16 at 10:41
  • Where do you set the value of `self.pendingShipmentDAO`? – Jelly Mar 23 '16 at 10:45
  • In `APIRequest.m` file Im setting it as `@synthesize pendingShipmentDAO;` –  Mar 23 '16 at 10:49
  • and In APIRequest.h file, i have `@property (strong) NSManagedObjectModel *pendingShipmentDAO; ` –  Mar 23 '16 at 10:50
  • I mean, where do you assign a value to it? Like `self.pendingShipmentDAO = something`. A declared `@property` is nil by default. – Jelly Mar 23 '16 at 10:51
  • im not assigning it anywhere. –  Mar 23 '16 at 10:55
  • From what I understand you want to check if the shippment already exists and update it if it does. So you should assign to `self.pendingShipmentDAO` the existing shippment if there is one or nil if it doesn't. – Jelly Mar 23 '16 at 11:00
  • Check this http://stackoverflow.com/questions/32066936/how-to-check-if-object-exists-in-core-data answer on how to check if an entity already exists in core data. – Jelly Mar 23 '16 at 11:01