Amazon.com Widgets Recent Posts
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 31, 2014, 09:42:43 PM
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
|-+  Recent Posts
Pages: 1 2 [3] 4 5 ... 10

 21 
 on: October 13, 2014, 10:12:37 AM 
Started by windallt23 - Last post by windallt23
just to show separating interface and implementation files is all and how to link them together

 22 
 on: October 12, 2014, 02:41:50 PM 
Started by jonr - Last post by BrianLawson
That is possible, I don't know for sure though.

 23 
 on: October 12, 2014, 01:36:29 PM 
Started by jonr - Last post by jonr
....Brian,

The mystery continues Smiley.  I tried running the simple code example in Xcode 5.0 and I'm getting the same results as Xcode 5.1.1.  As I stated in the original post, the results are different than the book.  In my last post I stated that the book appears to be using Xcode 5.0 based on the screen capture that is at the beginning of the book.  Perhaps this example is from an earlier printing of the book where a version of Xcode 4.x was used and the book hasn't been updated properly since then?
thanks,
jonR

 24 
 on: October 12, 2014, 11:34:32 AM 
Started by windallt23 - Last post by BrianLawson
As I said in my first response to this thread, for this problem classes are not needed. Why do you want a myMath class? What is its purpose?

 25 
 on: October 12, 2014, 11:26:29 AM 
Started by windallt23 - Last post by windallt23
Thanks for that help i see a lot that i didn't understand and i have changed some stuff around to to get the look i wanted. also how would i break this code up into other classes for instance a main.m and a myMath.h, and myMath.m? i can provide what i have if you want to use your code as an example. once i see how stuff works i can usally catch on and run with it i just have hard time adding things together and doing it all from scratch. this was so much help thanks again!

 26 
 on: October 11, 2014, 09:44:40 AM 
Started by jonr - Last post by jonr
Brian,
Thanks for this info.  I think I got a little lazy checking to see if the cause was an Xcode version issue.  I have a 4th edition hard copy and a 6th edition eBook version and on my 6th edition copy of the book I can see by the printing date and looking at various Xcode release dates that an Xcode version < 5.1.1 had to be used for the book.  Sure enough when looking at the screen captures at the beginning of the book, I see that version 5.0 was used.  When reading up on some of the changes between Xcode 5.0 and 5.1 / 5.1.1, compiler changes were in the feature list.

Btw, I would think that having the compiler be able to flag this before you attempt a build would be considered an improvement.  Do you agree?  It just seems to me that it's more intelligent and proactive in finding code problems.

Thanks for explaining that compile/build is essentially the same thing.  I must need a new pair of glasses Smiley as I see that Build (Command-B) is listed right there in the Product menu and I do see Compile in Product -> Perform Action.  Thanks for taking the time for pointing this stuff out.

Btw, I do have Xcode 6 installed but I've been using 5.1.1 for the book thinking that it may be better to use a version closer to the book's version . I may install 5.0 just to get completely in sync with the book in case there are other issues such as this one.
Cheers,
jonR

 27 
 on: October 10, 2014, 09:19:03 PM 
Started by windallt23 - Last post by BrianLawson
how do i create list such, for the user to choose what type of math the user wants to use such as choose:
1. addition
2.subtraction
3. multiplication
4. division

Use a series of NSLog statements as a prompt or just prompt the mathematical operator wanted and accept a char from the user. Reading a single character has some problems to work around when an invalid operator is entered. Here is one way to do this program using the char input method:
Code: (Objective-C)
#import <Foundation/Foundation.h>

// Generate random number between 1 and 20
int getRandomNumber() {
return (arc4random()%(20-1))+1;
}

int main(int argc, const char * argv[])
{
@autoreleasepool
{
// How many questions are to be asked
const int numQuestions = 5;

// For counting the number of correct answers
int correct = 0;

for (int i = 0; i < numQuestions; ++i) {
NSLog (@"Problem %i", i + 1);

float answer = 0.0;

// random number generator
int rnum1 = getRandomNumber();
int rnum2 = getRandomNumber();

// select math type
char operator;

// When scanf is used, the Enter character the user presses to enter the answer
// is also put into the buffer. The next read for a character will see that Enter
// character. throwAway is used to prevent operater from reading that Enter character.
char throwAway;

NSLog (@"please select math operation:");
scanf("%c", &operator);

BOOL validOperator = true;
// calculate answer to problem or display invalid operator error message
switch(operator)
{
case '+':
answer = rnum1 + rnum2;
break;
case '-':
answer = rnum1 - rnum2;
break;
case '*':
answer = rnum1 * rnum2;
break;
case '/':
answer = (float)rnum1 / (float)rnum2;
break;
default:
validOperator = false;
NSLog(@"ERROR: Invalid math operator %c", operator);
--i; // Don't count an invalid operator in the number of questions asked.
scanf("%c", &throwAway); // Clear the enter character from the input buffer.
break;
}

if (validOperator) {
NSLog(@"%i %c %i = ", rnum1, operator, rnum2);

// user enter answer to problem
float number;

scanf ("%f%c", &number, &throwAway);

if (number == answer ) {
++correct;
} else {
NSLog(@"The correct answer is %.1f", answer);
}
}
}

// Display results
// %% needed to print single % in results message
NSLog(@"Your score is %.1f%%, you missed %i questions.", ((float)correct / numQuestions * 100), (numQuestions - correct));
}

return 0;
}

 28 
 on: October 10, 2014, 06:56:21 PM 
Started by windallt23 - Last post by windallt23
how do i create list such, for the user to choose what type of math the user wants to use such as choose:
1. addition
2.subtraction
3. multiplication
4. division

then have the two random numbers do the type of math selected. this is what i have so far.
#import <Foundation/Foundation.h>
#import "myMath.h"

int main(int argc, const char * argv[])
{

    @autoreleasepool
    {
        // 5 loops before calculating percentage
        int count = 1;
        while (count <= 5){
            NSLog (@"%i", count);
            ++count;
           
        // select math type
            enum equation {1. = add, sub, mult, divi};
            enum equation entry;
            NSLog (@"please select equation");
            scanf("%i", &entry);
           
            switch(entry)
            {
                case 1:
                    NSLog(@"addition");
                case 2:
                    NSLog(@"subtraction");
                case 3:
                    NSLog(@"multiplication");
                case 4:
                    NSLog(@"division");
            }
       
        // random number generator
        myMath *myMathStuff;
        myMathStuff = [[myMath alloc] init];
       
        int rnum1 = [myMathStuff getRandomNumber];
        int rnum2 = [myMathStuff getRandomNumber];

       
        NSLog(@"The random numbers are %i and %i", rnum1, rnum2);
       
        // user enter answer to problem
        int number;
       
        NSLog (@"Type in your answer:");
        scanf ("%i", &number);
       
       
        }
    }
   
    return 0;
}

 29 
 on: October 10, 2014, 06:21:51 PM 
Started by jonr - Last post by BrianLawson
You are seeing a different error message because you are using a different version of Xcode than what was being used when the book was written. Depending upon exactly which version of Xcode the author was using you could even be using a completely different compiler. That could also explain why the program would run in the older version but not in the newer version.

To compile without running the program, use the Build command (Command-B). While technically different, in Xcode, a compile and build is essentially the same thing. Look under the Program menu's Perform Action command and there may be a Compile command for you. This will compile just the file you are currently displaying in the editor. I'm using Xcode 6 now so I can't check to see it that was available in Xcode 5.

 30 
 on: October 10, 2014, 05:39:48 PM 
Started by jonr - Last post by jonr
In chap. 9 there is a simple example in the section 'Compile Time Versus Runtime Checking' and shows what happens when you send an incorrect method to an instance.  The example uses a simple situation based on programs 9.1 and 9.2 where there are two classes, Fraction and Complex.  A fraction object is sent a message that is from the Complex class:
Code: (Objective-C)
[f1 setReal: 10 and Imaginary: 2.5];
  The books says that the following message is issued when you compile the program that contains this line:
Quote
"'Fraction' may not respond to 'setReal:andImaginary:'"
  This is easily understandable but I'm not seeing this exact result.  For me, in Xcode 5.1.1 flags this as an error and it won't even build.
Quote
The message states "No visible @interface for 'Fraction' declares the selector 'setReal:andImaginary:'"
  In other words I see this message displayed right in main.m. If I ignore the message and try to 'Run' I get a 'Build Failed' message.

Why am I seeing an outcome different from the book?  Is there a setting in Xcode that determines this?  One thing I can't figure out in Xcode is how to do a Compile without Running.  If it's possible in Xcode, I can't figure out where in the UI to do that.  I'm thinking that this could be the problem, but I'm not sure.  In fact, putting aside the issue of actually running the code, is there a way in Xcode to just do a Compile and not a full Build? I'm thinking that this could be the reason I'm seeing different results, but again I'm not sure. Any info would be most welcomed!
thanks,
jonR

Pages: 1 2 [3] 4 5 ... 10


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.