【问题标题】:How to enable optional parameters in IOS for Google App Engine endpoints如何在 IOS 中为 Google App Engine 端点启用可选参数
【发布时间】:2015-12-03 17:37:13
【问题描述】:

我已经创建了一个后端 API 项目,并且在没有传递任何参数的情况下成功调用了我的应用程序中的端点公开的 API。

GTLQueryNewerAPI *query = [GTLQueryNewerAPI queryForMymodelList];

此方法设计为带有可选参数。如生成 Google API 发现服务所示:

// Method: newerAPI.mymodel.list
//  Optional:
//   pupil: NSString
//  Authorization scope(s):
//   kGTLAuthScopeNewerAPIUserinfoEmail
// Fetches a GTLNewerAPIMyModelCollection.
+ (instancetype)queryForMymodelList;

我想在调用 API 时传递一个瞳孔参数,但这样做有困难。

NSString *pupil = @"Test Name";
GTLServiceNewerAPI *service = [self helloworldService];
GTLQueryNewerAPI *query = [GTLQueryNewerAPI queryForMymodelList:(NSString*)pupil];

选择器“queryForMymodelList:”没有已知的类方法

【问题讨论】:

    标签: ios google-app-engine google-cloud-endpoints endpoints-proto-datastore


    【解决方案1】:

    因为pupil 是一个可选参数,所以它不会为它生成构造函数 - 将它放在构造函数中会使创建GTLQueryNewerAPI 的实例需要它。

    您所要做的就是:

    NSString *pupil = @"Test Name";
    GTLServiceNewerAPI *service = [self helloworldService];
    GTLQueryNewerAPI *query = [GTLQueryNewerAPI queryForMymodelList];
    query.pupil = pupil;
    

    您应该会看到在 GTLQueryNewerAPI 的头文件中声明的 pupil 属性(通常类似于以下内容:

    @interface GTLQueryNewerAPI : GTLQuery
    //
    // Parameters valid on all methods.
    //
    
    // Selector specifying which fields to include in a partial response.
    @property (nonatomic, copy) NSString *fields;
    
    //
    // Method-specific parameters; see the comments below for more information.
    //
    @property (nonatomic, copy) NSString *pupil;
    
    ...
    @end
    

    pupil 属性(如果这样声明)旨在在需要时设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-16
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      相关资源
      最近更新 更多