简体   繁体   English

如何在IOS中为Google App Engine端点启用可选参数

[英]How to enable optional parameters in IOS for Google App Engine endpoints

I have created a backend API project and am successfully calling the API exposed by the endpoints within my App when no parameters are passed. 我创建了一个后端API项目,并且在没有传递任何参数的情况下,成功调用了我的应用程序中的端点公开的API。

GTLQueryNewerAPI *query = [GTLQueryNewerAPI queryForMymodelList];

This method has been designed with an optional parameter. 此方法设计有一个可选参数。 As seen in the generate Google API Discovery Service: 如生成Google API发现服务中所示:

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

I would like to pass a pupil parameter when calling the API but I am having difficulty doing so. 我想在调用API时传递一个瞳孔参数,但是这样做很困难。

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

No known class method for selector 'queryForMymodelList:' 选择器'queryForMymodelList:'的未知类方法

Becuase pupil is an optional parameter, it doesn't generate a constructor for it - putting it in the constructor would make it required for creating an instance of GTLQueryNewerAPI . 因为pupil是一个可选参数,它不会为其生成一个构造函数-将其放在构造函数中将使其成为创建GTLQueryNewerAPI实例所GTLQueryNewerAPI

All you have to do is the following: 您所要做的只是以下几点:

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

You should see the pupil property declared in the header file for GTLQueryNewerAPI (usually something like the following: 您应该看到在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

That pupil property, if so declared, is intended to be set when needed. 如果声明了该pupil属性,则应在需要时设置它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM