Search Results

Search found 3 results on 1 pages for 'mattyw'.

Page 1/1 | 1 

  • Getting MAX_INT from NSDateComponents

    - by MattyW
    I'm trying to write my first iPhone app, and I'm using a date picker object for the user to enter their date of birth. Part of my app requires the year in int format. I've added the code as below. What's odd is that 'month' gets the right value. But day and year seem to be stuck at MAX_INT (2147483647). Can anyone tell me what I'm doing wrong? -(IBAction)dateOfBirthChanged:(id)sender { NSCalendar* calender = [NSCalendar currentCalendar]; NSDateComponents* dateComponents = [calender components:NSMonthCalendarUnit fromDate:[datepicker date]]; NSInteger day = [dateComponents day]; NSInteger month = [dateComponents month]; NSInteger year = [dateComponents year]; label.text = [NSString stringWithFormat:@"Your year of birth is %d", year]; }

    Read the article

  • What's up with this reversing bit order function?

    - by MattyW
    I'm rather ashamed to admit that I don't know as much about bits and bit manipulation as I probably should. I tried to fix that this weekend by writing some 'reverse the order of bits' and 'count the ON bits' functions. I took an example from here but when I implemented it as below, I found I had to be looping while < 29. If I loop while < 32 (as in the example) Then when I try to print the integer (using a printBits function i've written) I seem to be missing the first 3 bits. This makes no sense to me, can someone help me out? int reverse(int n) { int r = 0; int i = 0; for(i = 0; i < 29; i++) { r = (r << 1) + (n & 1); n >>=1; } return r; }

    Read the article

  • Python module shared between multiple products

    - by MattyW
    I'm working on a python class that is being shared between two products. 90% of the functionality applies to both products. For the 10% that's different the code is littered with this kind of thing: #Start of file project = 'B' #Some line of code if project == 'A': import moduleA elif project == 'B': import moduleB #Many lines of code if project == 'A': print moduleA.doA(2) elif project == 'B': print moduleB.doB(2) This doesn't seem very elegant or very readable, has anyone encountered this sort of thing before? Are there better ways of doing it?

    Read the article

1