【问题标题】:Syntax Error in IOSIOS中的语法错误
【发布时间】:2017-08-03 13:23:05
【问题描述】:

我认为这是一个非常简单的问题,但我坚持了很长时间。我有一个函数,但遇到一些括号问题并且无法运行代码。我没有得到括号应该关闭的位置。

我的代码是,

-(void)Images{

    NSString *eachImagePath;
    if(_arrai.count == 0)
        return;

    eachImagePath = [NSString stringWithFormat:@"%@",_arrai[0]];

    NSMutableDictionary *dictAddNewJobImages = [[NSMutableDictionary alloc]init];
    dictAddNewJobImages[@"property_id"] = Propid;
    dictAddNewJobImages[@"name"] = _arrainame;

    NSString *strWebService = [NSString stringWithFormat:@"My URL"];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];

    [manager.requestSerializer setTimeoutInterval:600.0];

     [manager POST:strWebService parameters:dictAddNewJobImages constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData)
     {
         NSURL *filePath = [NSURL fileURLWithPath:eachImagePath];
         [formData appendPartWithFileURL:filePath name:@"image" error:nil];
     } progress:^(NSProgress * _Nonnull uploadProgress)
     {
     } success:^(NSURLSessionDataTask*  _Nonnull *task, id  _Nullable responseObject)
     {
         NSLog(@"%@",responseObject);
         [_arrai removeObjectAtIndex:0];
         if(_arrai.count > 0)
             [self Images];
     } failure:^(NSURLSessionDataTask*  _Nullable task, NSError*  _Nonnull error) {
         NSLog(@"%@",error);
      }
    }

【问题讨论】:

  • 将代码添加为文本而不是图像
  • `[manage POST: is missing的结尾
  • 是的,我要问的是如何结束它。 @詹斯
  • 如何使用]
  • 只需点击cmd+f 即可搜索{ 和} 以查看号码是否匹配。 [ 和 ] 相同。那么你至少知道要寻找什么。

标签: ios objective-c


【解决方案1】:

你忘记关闭你的区块}];

使用

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:XXXXXX parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: %@", responseObject);
 } failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}]; --> add the close in failure

而不是

[manager GET:XXXXXX parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: %@", responseObject);
 } failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}

更新答案

-(void)Images{

    NSString *eachImagePath;
    if(_arrai.count == 0)
        return;

    eachImagePath = [NSString stringWithFormat:@"%@",_arrai[0]];

    NSMutableDictionary *dictAddNewJobImages = [[NSMutableDictionary alloc]init];
    dictAddNewJobImages[@"property_id"] = Propid;
    dictAddNewJobImages[@"name"] = _arrainame;

    NSString *strWebService = [NSString stringWithFormat:@"My URL"];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];

    [manager.requestSerializer setTimeoutInterval:600.0];

     [manager POST:strWebService parameters:dictAddNewJobImages constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData)
     {
         NSURL *filePath = [NSURL fileURLWithPath:eachImagePath];
         [formData appendPartWithFileURL:filePath name:@"image" error:nil];
     } progress:^(NSProgress * _Nonnull uploadProgress)
     {
     } success:^(NSURLSessionDataTask*  _Nonnull *task, id  _Nullable responseObject)
     {
         NSLog(@"%@",responseObject);
         [_arrai removeObjectAtIndex:0];
         if(_arrai.count > 0)
             [self Images];
     } failure:^(NSURLSessionDataTask*  _Nullable task, NSError*  _Nonnull error) {
         NSLog(@"%@",error);
      }]; -- > close your block here
   }

【讨论】:

  • 我想运行我的代码,只是想设置我的代码我得到括号错误。 @Anbu.Karthik
  • @HamzaImran - 没问题,只需将此}]; 附加到NSLog(@"Error: %@", error); } 的位置,您的代码就可以使用NSLog(@"Error: %@", error); }]
  • @HamzaImran - 你从这里开始块 [manager POST 但没有关闭正确的块在这里关闭你的块 NSLog(@"Error: %@", error); }];
  • 我在这个成功中遇到了错误:^(NSURLSessionDataTask* _Nonnull *task, id _Nullable responseObject) 在我写你的代码时。@Anbu.Karthik
  • @HamzaImran - 您的代码很好且正确,只需关闭块即可查看我的更新答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-18
  • 1970-01-01
  • 2014-11-13
  • 2015-06-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多