如何将objective-c片段转换为Rubymotion

时间:2016-02-10 08:36:12

标签: objective-c rubymotion

我正在使用Rubymotion构建iOS应用。我需要"转换"这个Objective C代码变成了ruby。应该怎么样?我被卡住了。

ASRemoteIndex *index = [apiClient getIndex:@"YourIndexName"];
[index search:[ASQuery queryWithFullTextQuery:@"jim"]
  success:^(ASRemoteIndex *index, ASQuery *query, NSDictionary *answer) {

} failure:nil];

// setting some query parameters
ASQuery* query = [ASQuery queryWithFullTextQuery:@"jim"];
query.hitsPerPage = 5;
[index search:query success:^(ASRemoteIndex *index, ASQuery *query, NSDictionary *answer) {

} failure:nil];

1 个答案:

答案 0 :(得分:0)

像这样:

index.search(ASQuery.queryWithFullTextQuery("jim"), success:lambda do |index, query, answer|
       # optional block code here
    end, failure:nil)

query = ASQuery.queryWithFullTextQuery("jim")
index.search(query, success:lambda do |index, query, answer|
       # optional block code here
    end, failure:nil)

在此处阅读:RubyMotion Runtime Guide: Function Pointers and Blocks