Amazon.com Widgets 15.1 prints wrong number?
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 22, 2013, 05:21:33 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 15 - Numbers, Strings, and Collections
| | | |-+  15.1 prints wrong number?
Pages: [1]   Go Down
Print
Author Topic: 15.1 prints wrong number?  (Read 1074 times)
seerex
Full Member
***
Posts: 177


Email




« on: September 09, 2011, 06:09:41 AM »

Hello,

Page 310-311 (third edition) has a few NSLog calls, one which is this:
Code: (Objective-C)
// Wrong access here
NSLog (@"%li", (long) [myNumber integerValue]);

In the book, the value printed is 0, but i get: -9223372036854775808

Does this just has something to do with the fact i am using Xcode, or do you suspect i mistyped something?
Logged

Best Regards -
J.B.J
If you think i helped you could return the favor Wink

Subscribe to my channel on youtube: http://www.youtube.com/user/JBJProgramming

My apps:
- iTap Fruits (all countries)
- Toilet-Quiz (Denmark only)
- Zoo Kids (Denmark only)
- Diablo Item Database (All countries)
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #1 on: September 09, 2011, 08:44:27 AM »

I think it is an error in the book.  If you cast it as an integer:
NSLog(@"%i", (int)[myNumber integerValue]);
you get 0.
Logged
seerex
Full Member
***
Posts: 177


Email




« Reply #2 on: September 09, 2011, 08:50:52 AM »

Ah okay thanks Fujilla, must be an error then Smiley

May i ask, what did you do in chapter 13? about the underlying C language features? it says you can either a. read after part 2 on the foundation framework or b. skip all together and reference back to it when / if needed?

What did you do? Smiley
Logged

Best Regards -
J.B.J
If you think i helped you could return the favor Wink

Subscribe to my channel on youtube: http://www.youtube.com/user/JBJProgramming

My apps:
- iTap Fruits (all countries)
- Toilet-Quiz (Denmark only)
- Zoo Kids (Denmark only)
- Diablo Item Database (All countries)
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #3 on: September 09, 2011, 08:54:42 AM »

I decided not to read Chapter 13, however feel that maybe I should have so will be going back to it, especially in relation to blocks and structures.
Logged
seerex
Full Member
***
Posts: 177


Email




« Reply #4 on: September 09, 2011, 10:47:28 AM »

Okay thanks mate, i'll wait till i come across it later Smiley

-argh a final question, sorry for being a pain - i was wondering if it's ok not to be able to understand the classes written by apple in the foundation framework? i mean sure i can get most of it and at least i'm able to notice a few things, but the bigger picture i can't really see. For instance the NSDecimalNumber or something like that which the book said you should examine. is it ok if i don't really understand it all? coz if i have to understand it all i'm missing something vital.

So it's pretty much a "i'm ok" question Smiley to ease my nerves hehe. Thanks on advance Fujilla, good luck on the development with your app btw! looks great
Logged

Best Regards -
J.B.J
If you think i helped you could return the favor Wink

Subscribe to my channel on youtube: http://www.youtube.com/user/JBJProgramming

My apps:
- iTap Fruits (all countries)
- Toilet-Quiz (Denmark only)
- Zoo Kids (Denmark only)
- Diablo Item Database (All countries)
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #5 on: September 09, 2011, 11:07:31 AM »

Personally, I would say that one cannot be expected to remember everything.  The Foundation Framework and the others are very big, that I doubt there is anyone out there that knows it all.  What you will find is that you will know roughly the code you need to do something and will look it up in the documentation to get the exact methods etc...

One of the big things with iOS apps is probably the UITableView, something that a heck of a lot of apps use to display data.  I am starting to remember which methods I need and have printed out the most common ones and stuck it to the wall next to my mac, so that at a glance I can remind myself.

One thing which I haven't utilised yet is code snippets which can be very handy when you use certain blocks of code time and time again, and I'm sure I will start using that some time soon.

As for my app I have actually submitted it to Apple ;-)  I submitted it yesterday, however realised I didn't submit it properly which was a bonus as I had made a couple of changes after submitting it so resubmitted it today.

It was a bit of a nightmare to begin with - setting up the certificate in the keychain access (that scares me for some reason), then you need a distribution profile for every app you want to submit to the app store, then you have to make further changes within the project... the list goes on.

Also, one aspect that can be time consuming is designing the icons inside the app (for the tab bar in my case), and the icons for the app itself.  The app icon was a nightmare as what I initially designed didn't downsize very well from 512 x 512 pixels for the app store version to 57 x 57 pixels for the pre iPhone 4 version.

Anyway, fingers crosses all goes well with the review of the app, and maybe this time next week I will have some more news.

Nick
http://myfirstiphoneapp.co.uk
Logged
skochan
Administrator
Hero Member
*****
Posts: 3103







« Reply #6 on: September 09, 2011, 11:36:30 AM »

I think it is an error in the book.  If you cast it as an integer:
NSLog(@"%i", (int)[myNumber integerValue]);
you get 0.

myNumber contains a float value, so the point of that statement was to show that you get the wrong value from an NSNumber if you don't use the correct method.   It doesn't matter what the output actually is (and it's not necessarily defined), but the point is that it's the wrong answer.

Cheers,

Steve
Logged
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #7 on: September 09, 2011, 11:43:27 AM »

Sorry Steve, what I meant by "an error in the book", is that you say in the book the output is 0, so this may confuse people to thinking they are getting the wrong result.
Logged
skochan
Administrator
Hero Member
*****
Posts: 3103







« Reply #8 on: September 09, 2011, 11:48:20 AM »

No problem.  I should note in the text that you may not get 0 displayed for that statement.

Cheers,

Steve
Logged
loumaag
Newbie
*
Posts: 2






« Reply #9 on: September 15, 2011, 01:41:45 PM »

myNumber contains a float value, so the point of that statement was to show that you get the wrong value from an NSNumber if you don't use the correct method.   It doesn't matter what the output actually is (and it's not necessarily defined), but the point is that it's the wrong answer.

Cheers,

Steve
Oddly enough, I think you get the right answer, based on value.  When I got the same result as the OP here, i started playing with the value. Initially going into this part of the program, the value of myNumber is actually a double.  When I changed the number assigned there to 12345e+3 the output of the next section is actually 12345000, which is correct. I think the initial value of  12345e+15 just ran it over the long integer max and into the negative values.  Below is the code for those two sections and the result I got (note, I use printf as opposed to NSLog):

Code: (Objective-C)
    
    // double
    myNumber = [NSNumber numberWithDouble:12345e+3];
    printf("%lg\n", [myNumber doubleValue]);
   
    // wrong access here
    printf("%li\n", (long) [myNumber integerValue]);
   
...
1.2345e+07
12345000
...
Logged
symeon
Newbie
*
Posts: 1







« Reply #10 on: October 30, 2011, 03:41:40 AM »

Hello everyone!

Well, I had exactly the same problem with seerex..

After further digging, I found that changing 64-bit compilation to
32-bit architecture the value is indeed 0 and not -9223372036854775808.

I guess 64bit compilation treats differently our value and thus everything is correct
on the book.

p.s. thanks Steve for your fantastic book & your support
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.