Converting integer to text value for IB

10 views
Skip to first unread message

marcio

unread,
Nov 17, 2009, 5:31:10 PM11/17/09
to iPhone Application Development Auditors
Im retrieving an integer value from a sqlite table like this:

placeObj.placeRating = [NSString
stringWithFormat:@"%i",sqlite3_column_int(selectstmt, 0)];

and then i pass this value to the detailviewController and i set a
UILabel's value to it. I get garbage when i log it....

Whats the correct way to do this? ive googled around to no avail so
far...

Sukima

unread,
Nov 18, 2009, 2:35:27 AM11/18/09
to iPhone Application Development Auditors
How are you logging it? It is very possible that your reference to the
created NSString is being release under your nose. Try assigning it to
variables so you can use the debugger:

int myNum = sqlite3_column_int(selectstmt, 0);
NSString myStr = [[NSString alloc] initWithFormat:@"%i", myNum];
NSLog(@"myStr = %@", myStr);
[myStr release];

in fact an NSNumber could be used here:

NSNumber myNum = [[NSNumber alloc] initWithInt:sqlite3_column_int
(selectstmt, 0)];
NSLog([myNum stringValue]);
[myNum release];

See if that helps. If not use the sqlite3 command line to make sure
the value is correct in the database.

marcio

unread,
Nov 18, 2009, 5:15:45 PM11/18/09
to iPhone Application Development Auditors
When i do this:

NSNumber *myNum = [[NSNumber alloc] initWithInt:sqlite3_column_int
(selectstmt, 0)];
NSLog("%@", myNum);
[myNum release];

marcio

unread,
Nov 18, 2009, 6:45:14 PM11/18/09
to iPhone Application Development Auditors
Sorry, something happened to my last post. I meant to say, when i use
the NSNumber, although the column is of type Numeric Integer in
sqlite, i get an error of BAD EXC ACCESS....but when i use the
NSString it works fine! I mean it logs fine.

marcio

unread,
Nov 18, 2009, 7:07:11 PM11/18/09
to iPhone Application Development Auditors
Id like to understand this...im declaring a property to my Place class
like so:

NSString *placeRating;

Then i read the value from a sqlite db like so:

placeObj.placeRating = [NSString
stringWithFormat:@"%i",sqlite3_column_int(selectstmt, 0)];

this logs fine as explained before. The column type is Numeric. So
as I udnerstand, cocoa takes the numeric value and makes it into a
String value via stringWithFormat and stores it in an appropriate
NSString *placeRating. I have another ivar called placeDescription
which is the same, an NSString but uses this to read from the
database:

placeObj.placeDescription = [NSString stringWithUTF8String:(char *)
sqlite3_column_text(selectstmt, 2)];

But when i log %@ the NSString *placeDescription i get my text,
however when i log %@ my placeRating value i get garbage and more
recently, this:

kCGColorSpaceModelMonochrome 0 0....

So im trying to udnerstand....if ive stored NSString *placeRating in
the placeObj.placeRating as a stringWithFormat, it should be an
NSString object right? So why isnt it logging like its other ivar
counterparts, namely NSString *placeDescription?

I FIGURED IT OUT.....I was assigning it, not copying it or retaining
it....memory management...i thought it might be since i was getting
different garbage everytime i logged it. Could this be a rule of
thumb? If i log a variable and get different garbage each time, its
because its value has been lost and its just grabbing any value from
memory?






On Nov 18, 4:15 pm, marcio <quique...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages