March 24, 2018, 06:34:27 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Read this please.
♦
The Great Kangaroo Escape
♦
Looking for reviews of the 4th ed on Amazon!
♦
Twitter:
@skochan
Home
Help
Search
Login
Register
Chat
Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
>
Old Stuff
>
Chapter Study
>
Chapter 7 - More on Classes
>
Allocating and returning Objects from Methods HeLp!
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: Allocating and returning Objects from Methods HeLp! (Read 1729 times)
macifone
Newbie
Posts: 14
Allocating and returning Objects from Methods HeLp!
«
on:
November 05, 2009, 02:57:24 PM »
I have trouble on the bottom of page 150 where it starts talking about, like the title says, allocating and returning objects.
So I get that a new object called result is being made, why is resultNum and resultDenom being made?
Dosnt result fraction object already have its own members (instance vars) of numerator and denominator?
Or am I missing something?
Back on page 144 where it starts the add: method I think I got confused with where it says
numerator1 = numerator * f.denominator
...
denominator1 = denominator * f.denominator
Isnt numerator1 and denominator1 (i just put 1 after it to tell difference) instance vars of what?
I am so confused.
I have no idea what anyhting is.
PLEASEE HELPPP MEEEEE!
Logged
skochan
Administrator
Hero Member
Posts: 3114
Re: Allocating and returning Objects from Methods HeLp!
«
Reply #1 on:
November 05, 2009, 03:18:35 PM »
resultNum
and
resultDenom
are just temporary variables used to hold the result of calculating the numerator and denominator, respectively, of the result of the addition of the two fractions. The values in these two variables are then used to set the numerator and denominator of the
result
fraction with the subsequent
setTo:over:
method call.
When
numerator
and
denominator
are used by themselves in the method, they refer to the corresponding instance variables of the
Fraction
object that got sent the
add:
message (i.e, the message receiver). Remember, that's always the case: you can reference the receiver's instance variables directly by name. On the other hand, the expressions
f.numerator
and
f.denominator
are used to reference the numerator and denominator, respectively, of the argument to the
add:
method (which we call
f
).
Hope this helps.
Cheers,
Steve Kochan
Logged
macifone
Newbie
Posts: 14
Re: Allocating and returning Objects from Methods HeLp!
«
Reply #2 on:
November 05, 2009, 03:34:45 PM »
Thanks now I get it, also because its returning result the add: method has a return typr of fraction?
On page 151 and 152, why is the object resultFraction made couldnt the program 7.5 work without that?
Cause all it does is store the output of [aFraction add: bFraction];
and then prints it.
Thanks for helping.
Logged
skochan
Administrator
Hero Member
Posts: 3114
Re: Allocating and returning Objects from Methods HeLp!
«
Reply #3 on:
November 05, 2009, 08:20:25 PM »
It's stored so it can be released later. Read the sticky at the top of this topic.
Cheers,
Steve Kochan
Logged
Pages: [
1
]
Go Up
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Programming in Objective-C, 5th edition
-----------------------------
=> General Discussions
=> Exercises
-----------------------------
Programming in Objective-C, 4th edition
-----------------------------
=> General Discussion
=> Exercises
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 14
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 20
===> Chapter 21
=> Chapter 2
=> Chapter 3
=> Chapter 4
=> Chapter 5
=> Chapter 6
=> Chapter 7
=> Chapter 8
=> Chapter 9
=> Chapter 10
=> Chapter 11
=> Chapter 12
=> Chapter 13
=> Chapter 14
=> Chapter 15
=> Chapter 16
=> Chapter 17
=> Chapter 18
=> Chapter 19
=> Chapter 20
=> Chapter 21
=> Errata
===> 1st Printing
===> 2nd Printing
-----------------------------
Members' Corner
-----------------------------
=> Look What I'm Doing...
-----------------------------
Study Group
-----------------------------
=> Objective-C Quizzes
===> Comprehensive Quiz
===> Chapter 1 - Introduction
===> Chapter 2 - Programming in Objective-C
===> Chapter 3 - Classes, Objects, and Methods
===> Chapter 4 - Data Types and Expressions
===> Chapter 5 - Program Looping
===> Chapter 6 - Making Decisions
===> Chapter 7 - More on Classes
===> Chapter 8 - Inheritance
===> Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
===> Chapter 10 - More on Variables and Data Types
===> Chapter 11 - Categories and Protocols
===> Chapter 12 - The Preprocessor
===> Chapter 15 - Numbers, Strings & Collections
===> Chapter 17 - Memory Management
-----------------------------
iOS Programming
-----------------------------
=> General Questions
-----------------------------
Programming in C, 3rd ed. (Stephen Kochan)
-----------------------------
=> Programming in C webcasts?
=> Answers to Odd-Numbered Exercises
=> Questions and Help
-----------------------------
Old Stuff
-----------------------------
=> Errata, Answers to Exercises, Code, etc.
=> Shared Code Library
=> Welcome
=> News
=> Errata
===> 1st Printing
===> 2nd printing
=> Newbie Corner
=> Chapter Study
===> Chapter 2 - Programming in Objective-C
===> Chapter 3 - Classes, Objects, and Methods
===> Chapter 4 - Data Types and Expressions
===> Chapter 5 - Program Looping
===> Chapter 6 - Making Decisions
===> Chapter 7 - More on Classes
===> Chapter 8 - Inheritance
===> Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
===> Chapter 10 - More on Variables and Data Types
===> Chapter 11 - Categories and Protocols
===> Chapter 12 - The Preprocessor
===> Chapter 13 - Underlying C Language Features
===> Chapter 15 - Numbers, Strings, and Collections
===> Chapter 16 - Working with Files
===> Chapter 17 - Memory Management
===> Chapter 18 - Copying Objects
===> Chapter 19 - Archiving
===> Chapter 21 - Writing iPhone Applications
=> Answers to Exercises
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 21
=> General Discussion
=> Program Examples
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 21
=> XCode 4 Help
=> Suggestions
=> Help!!!
=> Fraction Calculator Available from the App Store
=> Resources
=> Errata
===> 1st & 2nd printings
===> 3rd & 4th printings
===> 5th printing
===> Current Errata
=> Suggestion Box
=> Tips & Tricks
=> Part 3
===> Welcome to the Class
===> Special Announcements
===> Assignments
=> Parts 1 and 2
===> Welcome to the Class
===> Questions and Discussion
===> SPECIAL ANNOUNCEMENTS
===> Assignments
===> Chapter 4, Exercise 7
===> Suggestions
=> Webcast Series Part I, Sept. 1 - 24
===> Welcome
===> SPECIAL ANNOUNCEMENTS
===> Questions and Discussion
===> Assignments
===> Chapter 4, Exercise 7
===> Chapter 6, Exercise 4
===> Suggestions
=> Webcast Series Part II, Oct. 1 - 27
===> Welcome
===> SPECIAL ANNOUNCEMENTS
===> Questions and Discussion
===> Assignments
===> Example using hasPrefix: and hasSufix:
===> Suggestions
=> Objective-C Workshop Aug 11 - 13
=> Webcast Series Part I, Oct. 29 - Dec. 1
===> Welcome
===> SPECIAL ANNOUNCEMENTS
===> Assignments
===> Chapter 4, Exercise 7
===> Chapter 6, Exercise 4
===> Suggestions
=> Webcast Series Part II, Jan 5 - 28
===> Welcome
===> SPECIAL ANNOUNCEMENTS
===> Assignments
===> Jan 7th Solutions
Loading...