6

I am migrating an iOS app from Xcode4 to Xcode7 (beta 4). Dependency to AFNetworking is automatically resolved via Pods. AFNetworking 2.0 is not backwards compatible with AFNetworking 1.0 so I modified part of the source. Here is

  • File structure
  • Log and
  • the related Source code

Issue below

/Api/ApiClient.m::: error: unexpected interface name 'NSData': expected expression
                NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding];
                ^

/Api/ApiClient.m::: error: use of undeclared identifier 'callerData'
                NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding];

at line 280 of the example above

enter image description here

Substituting NSData with NSString results in the error below

enter image description here

Original AFNetwork-1.0 code below

enter image description here

I try to migrate to AFNetwork-2.0 by replacing the routine with either //1

enter image description here

or //2

enter image description here

without any success

Nikolaos Giotis
  • 281
  • 2
  • 23

2 Answers2

7

I think the NSData compiler error is a red herring. The problem is that you are only provided a code block for the 'failure' argument rather than the 'constructingBodyWithBlock' argument.

Try something like:

NSMutableURLRequest* request = 
[ [ApiManager sharedManager] 
POST:@"/v1/exec"
    parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
        {
            // Code to form the body of the form is here

            //NSData* callerData = [[NSData alloc] init];
            NSData* callerData = [@"http://nikyotis.xyz" dataUsingEncoding:NSUTF8StringEncoding];
            [formData appendPartWithFormData:callerData name:@"caller"];
            [formData appendPartWithFileData:fontData name:@"front" fileName:@"front" mimeType:@"application/octet-stream"];
            [formData appendPartWithFileData:sideData name:@"side" fileName:@"side" mimeType:@"application/octet-stream"];
        }
       success:^(AFHTTPRequestOperation *operation, id responseObject)
        {
            // Operation success code goes here
        }

       failure:^(AFHTTPRequestOperation *operation, NSError *error)
        {
            // Operation failed code goes here
        }
 ];

apologies for any formatting issues - having markdown trouble.

Richard Groves
  • 3,596
  • 3
  • 21
  • 21
  • i 've already tried what you suggest - check latest screenshots with code commented out (//1, //2) – Nikolaos Giotis Aug 04 '15 at 18:48
  • 1
    No - both of those listings have no body for the first two block arguments. Look where I have the { } sections in the answer above. In your listings (both //1 and //2) you just have one block of { } code for the last argument of the method call. – Richard Groves Aug 05 '15 at 12:26
4

problem was the unstable (beta)

OS X El Capitan 10.11 Beta (15A244d) | Xcode Version 7.0 beta 4 (7A165t)

I was using. what i was expecting really...

the code above runs fine on stable Yosemite n Xcode 6.4

Nikolaos Giotis
  • 281
  • 2
  • 23