通过参数NSInteger返回值
我需要从数据库读取 3 个值并在方法中返回它们。我无法理解如何使用 NSInteger 类型返回值。这是代码:
NSString* GetVerbInfinitive(FMDatabase* mydb, NSString* myConjugation, NSInteger verbal_time, NSInteger verbal_person)
{
NSMutableString *ret = [[NSMutableString alloc] initWithString:@""];
FMResultSet *rs = [mydb executeQuery:@"select verb_text, conjugation_verbal_time, conjugation_verbal_person from verbs where verb_conjugation = ?",[[myConjugation lowercaseString] precomposedStringWithCanonicalMapping]];
if ([rs next])
{
if (![rs columnIndexIsNull:0])
{
[ret setString:[rs stringForColumn:@"verb_text"]];
verbal_time = [rs intForColumn:@"conjugation_verbal_time"];
verbal_person = [rs intForColumn:@"conjugation_verbal_person"];
}
else
{
NSLog(@"GetVerbInfinitive: verb '%@' has no infinitive defined", myConjugation);
}
}
[rs close];
return [ret autorelease];
}
NSInteger 值仅在方法内部起作用,当我返回到调用方法时,它们会丢失。我相信我应该通过引用传递这些 NSInteger,但我不知道如何。我不想为此创建类型结构。
谢谢, 米格尔
I need to read 3 values from a database and return them in a method. I'm having trouble to understand how to return values using NSInteger types. This is the code:
NSString* GetVerbInfinitive(FMDatabase* mydb, NSString* myConjugation, NSInteger verbal_time, NSInteger verbal_person)
{
NSMutableString *ret = [[NSMutableString alloc] initWithString:@""];
FMResultSet *rs = [mydb executeQuery:@"select verb_text, conjugation_verbal_time, conjugation_verbal_person from verbs where verb_conjugation = ?",[[myConjugation lowercaseString] precomposedStringWithCanonicalMapping]];
if ([rs next])
{
if (![rs columnIndexIsNull:0])
{
[ret setString:[rs stringForColumn:@"verb_text"]];
verbal_time = [rs intForColumn:@"conjugation_verbal_time"];
verbal_person = [rs intForColumn:@"conjugation_verbal_person"];
}
else
{
NSLog(@"GetVerbInfinitive: verb '%@' has no infinitive defined", myConjugation);
}
}
[rs close];
return [ret autorelease];
}
The NSInteger values work only inside the method when I return to the calling method they are lost. I believe I should pass these NSInteger by reference, but I don't know how. I don't want to create a type structure for this.
Thanks,
Miguel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将它们作为指针取消引用。下面是一个示例(当您调用该方法时,这会出现在代码中):
现在在您的 getverbinfinitive 方法中:
请注意签名行中的更改,以生成这两个 NSIntegers 指针。
You have to dereference them as pointers. Here's an example (this goes in the code when you're calling the method):
Now in your getverbinfinitivemethod:
Notice the change in the signature line to make those two NSIntegers pointers.