这是我的第一个快速和谷歌应用引擎体验。
我创建了一个简单的java后端,制作了一个发现文档,使用了服务生成器(新的REST服务生成器)来创建客户端库,添加了所有google-specfic客户端库。
我无法在查询中传递编译器错误..
这是代码:
let service: GTLRHelloworldService = GTLRHelloworldService()
//no compiler problem with this line.
//my GTLRHellowworldService is included through the bridging headers
service.isRetryEnabled = true
set myquery: GTLRHelloworldQuery_GreetingsEstablishHandShake = GTLRHelloworldQuery_GreetingsEstablishHandShake.query()
service.executeQuery(myquery) { (ticket:GTLRServiceTicket, resp:GTLRHelloworld_HelloGreeting, error: NSError) in
nameLabel.text = resp?.message
}
错误在最后一行:
无法转换类型的值'(GTLRServiceTicket,GTLRHelloworld_HelloGreeting,NSError) - > ()'到期望的参数类型'GTLRServiceCompletionHandler?'
为了您的信息,servicegnerator创建的头文件中的GreetingsEstablishHandShake定义是:
/**
* GTLRHelloworldQuery_GreetingsEstablishHandShake
*
* Method: helloworld.greetings.establishHandShake
*
* Authorization scope(s):
* @c kGTLRAuthScopeHelloworldUserinfoEmail
*/
@interface GTLRHelloworldQuery_GreetingsEstablishHandShake : GTLRHelloworldQuery
// Previous library name was
// +[GTLQueryHelloworld queryForGreetingsEstablishHandShake]
/**
* Fetches a @c GTLRHelloworld_HelloGreeting.
*
* @returns GTLRHelloworldQuery_GreetingsEstablishHandShake
*/
+ (instancetype)query;
@end
并且头文件中的HelloGreeting对象是:
@interface GTLRHelloworld_HelloGreeting : GTLRObject
@property(nonatomic, copy, nullable) NSString *message;
@end
答案 0 :(得分:0)
我将swift代码翻译成了目标c。 我按照指示进去了 the very helpful google introduction for objective c for rest
我的代码现在运行并与服务器成功通信:
static GTLRHelloworldService *service = nil;
if (!service) {
service = [[GTLRHelloworldService alloc] init];
// Have the service object set tickets to retry temporary error conditions
// automatically
service.retryEnabled = YES;
//[GTMHTTPFetcher setLoggingEnabled:YES];
}
GTLRHelloworldQuery_GreetingsEstablishHandShake * query = [GTLRHelloworldQuery_GreetingsEstablishHandShake query];
GTLRServiceTicket *ticket = [service executeQuery:query
completionHandler:^(GTLRServiceTicket *callbackTicket,
GTLRHelloworld_HelloGreeting *resp ,
NSError *callbackError) {
_nameLabel.text = resp.message;}];
如果有人能帮助我了解如何在swift中翻译此代码,我将不胜感激,