1
I have a class that manages all my database, my project is in Swift but I have two classes in Objective-C to make the "bridge" between the classes and my Helper.
After some testing in iOS simulator I got the following error message:
Terminating app due to uncaught Exception 'Nsinvalidargumentexception', Reason: '***+[Nsstring stringWithUTF8String:]: NULL cString'
Why did this occur?
Follow my two classes:
SQLiteObjc.h
:
#import <Foundation/Foundation.h>
#import "sqlite3.h"
@interface SQLiteObjc : NSObject
+ (void) bindText:(sqlite3_stmt *)stmt idx:(int)idx withString: (NSString*)s;
+ (NSString*) getText:(sqlite3_stmt *)stmt idx:(int)idx;
@end
SQLiteObjc.m
:
#import "SQLiteObjc.h"
@implementation SQLiteObjc
+ (void) bindText:(sqlite3_stmt *)stmt idx:(int)idx withString: (NSString*)s {
sqlite3_bind_text(stmt, idx, [s UTF8String], -1, nil);
}
+ (NSString*) getText:(sqlite3_stmt *)stmt idx:(int)idx {
char *s = (char *) sqlite3_column_text(stmt, idx);
NSString *string = [NSString stringWithUTF8String:s];
return string;
}
@end
Thanks, it worked!
– Leonardo Rocha