Mark Worsnop
Mark Worsnop

Reputation: 4467

iphone method return NSString returns nothing

I am trying to understand how to return a NSString. The method checks the database field and returns "" or the value

What am I doing wrong?

- (NSString *) GetText:(char*) FieldName  compiledStatement:(sqlite3_stmt*)  cs {
    char *c = (char *) sqlite3_column_text(cs,  [self get_column_index:cs zName:FieldName] ) ;

    if (c != NULL)  return  (NSString *)c; else return @"";
}

calling the method:

User = [self GetText:"Name" compiledStatement:compiledStatement];

User is

NSString *User;

Upvotes: 0

Views: 234

Answers (1)

arclight
arclight

Reputation: 5310

Change your return line for

if (c != NULL)
    return [NSString stringWithCString:c encoding:NSUTF8StringEncoding];

return @""

Upvotes: 3

Related Questions