Welcome, Guest. Please login or register.
Did you miss your activation email?
February 25, 2017, 08:50:50 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
|-+Recent Posts
Pages: [1] 2 3 ... 10

 on: February 24, 2017, 06:50:44 AM 
Started by pif - Last post by nunof32

I just posted something very similar to this (Feb. 24, 2017) before I noticed your post.

I think your concern is valid. Have you had a full explanation on how and why this works (or not).



 on: February 24, 2017, 06:44:33 AM 
Started by nunof32 - Last post by nunof32
Hello, I'm trying to learn Objective-C and am stuck in Chapter 8. Would appreciate if someone can get me out of the rut.

My worries concern Class Rectangle that is introduced in this chapter (Cool.

1. First I'm troubled by the fact that nowhere is it said that Properties height and width of Rectangle must not be negative. If they can be negative, the definition of Property origin (coordinates of the lower left corner of the rectangle) makes that origin has to be recomputed (and the negative values of height / with converted to positives) each time height and width are (re)set. There are also a number of interesting complications if the user sets first the height and the width of the rectangle before setting its origin.

To avoid these complications I would like to ensure that height and width are >= 0. But as author Kochan has imposed earlier that these Properties are @synthesized I assume that the author does not wish that I tinker with their accessor methods ...

Any views on this ?

2. More fundamental : setOrigin method implementation. The book usefully highlights the problem that can occur if this method just copies into origin (which is a pointer) the parameter pt (also a pointer) that is passed to it : both pointers point to the same values and if the values that pt points to are changed so will the values that origin points to.

The book says that the solution is for the instance to own its own origin XYPoint. This is achieved through a preliminary statement at the beginning of the method

origin = [[XYPoint] alloc] init];

Very well. Now we have created our own XYPoint which origin points to.

My problem is that this looks strange. The statement is put inside the setOrigin method. Presumably, the XYPoint that it creates is created in memory space that belongs to the method for the duration of its execution. By the time the method returns, this space is reverted to the 'space unused' pool and nothing guarantees us that the space where the x and y property values of origin are stored will not be overwritten by someone else.

I would have thought that the right solution would be to make the allocation / initialization of the variable along with its declaration in this way :

@interface : Rectangle
   XYPoint origin * = [[XYPoint alloc] init]];

but this is not allowed.

Can someone please shed some light into this ?

Many thanks in advance.

 on: January 25, 2017, 02:45:48 AM 
Started by eagle74 - Last post by Jamepoison

Read the story here. It is knowledge that is very useful for me and for many people.

 on: December 04, 2016, 06:49:37 PM 
Started by JRIH - Last post by JRIH
Using Objective-C 6th edition and Xcode 6.3.
When I try to type in the initial program, into the different files: main.m Fraction.h and Fraction.m, I get error messages all over the place.
The Fraction.m file is actually named NSObject+Fraction.m. and inside it says to #import "NSObject+Fraction.h".
in main.m, when I put in Fraction *myfraction = [[Fraction alloc] init];, i get a warning that says "Fraction is undeclared".  I did put in the entire program before looking at the warnings.
These are just a couple of examples of many.
I followed the chapter 2 and Chapter 7 instructions, but nothing is going right.  I hope you can help me and let me know any further information that you may need.

 on: November 10, 2016, 08:54:20 PM 
Started by blur - Last post by blur
750+ downloads as of today!! Shocked Not a huge success.. but I'll take it..

 on: September 18, 2016, 08:19:50 AM 
Started by skbansal222 - Last post by skbansal222
I wanted to send you a quick message about my newly created video course on Linux OS! I really hope you will find this course to be a great resource for you.
1. Tired of finding good learning resources on Linux ?
2. Do you want to become a expert level Linux Engineer ?
3. Join 20k worldwide learners who uses Linux as part of their curriculum and Job.
4. As a dividend, get a complimentary consultation about Linux OS, Linux Internals and Linux Kernel.
5. So if youíre looking for knowledge, a rewarding adventure, and the advantage a future perspective can offer, Iím excited to tell you more about my step-by-step training program for Linux.
Claim your spot now without any cost
At the end of my course, you would be able to unlock the power of open-source technologies with expert training:
1. Understand the terminologies and concepts of Linux OS.
2. Learn the operation of Linux OS which is commonly used in most of the products being it Open source.
3. Expand your skills and career opportunities by mastering open-source technologies such as Linux, Ubuntu and more.
As you go through the course I'd love to get some review points and also find out if there are any other topics you would find helpful. If you have an extra minute and wouldn't mind leaving a review, I would greatly appreciate it!
If you ever have any questions at all please do not hesitate to contact me via the course discussion board or a private message. I am here to help you as you get started!
Enjoy and learn enough!
John Mathew

 on: September 10, 2016, 04:23:33 PM 
Started by pif - Last post by jonr
This is a good question and one that I never really thought about.  Well, at least in the context of object allocation within a method.  You are correct about how local variables work with regards to their scope.

I think why this is a special case is because in this example the variable (object) is a pointer.  So, it's creating a reference to a memory location, not merely assigning a value to a variable.  When you create a 'regular' variable in a method or function and initialize it, you are just assigning a value to the variable and not working at the memory address level.

I may not be doing the best job explaining this; probably someone more experienced could do a better job. 


 on: September 09, 2016, 06:37:50 PM 
Started by afterDark - Last post by jonr
I too noticed the same thing--I didn't have to rename the add: method in order to avoid any warnings or errors.  Out of curiosity I found the NSObjectController.h file and looked to see if there was an add: method and I didn't see one.  So it could be the book is now out of date re: this issue.  Perhaps the add: method was removed from that class?  I have no idea, but if so, this conflict shouldn't exist anymore.

Keep in mind, that there is more to this issue than simply the same method name when the receiver is not known (an id variable).  There has to also be a mismatch in the return type and argument type as discussed in the book.  That's what also has to happen to get the error.  And as the book points out, if the return type and argument type are objects, then there is no problem (even if they are different objects).  The problems arise when there are basic data types involved (int, float, etc.) and those don't match.  Btw, I believe the issue about different objects not causing a problem was illustrated to us implicitly in one of the chapter's programs before it was explicitly explained.  I think we saw this with the Complex and Fraction class both returning and taking as arguments their own types, with the same method name, with an id object as a receiver and no problems occurred.  Again, if the argument types hadn't been these objects and instead basic data types (that perhaps were different from one another (e.g. int vs float), this example in the book would have caused errors.

I created a simple test file to test this and found the book was correct on this, and particularly the fine points of the mismatched return and argument types (basic data types) and method names with the same name.  This is the error message that you would have received if the book's warning was correct:

Error:  Multiple methods named 'add:' found with mismatched result, parameter type or attributes

This error would have to be corrected before you could compile the code.

One more bit of detail:  The above error would have appeared if you had ARC enabled (which is now the default).  If you had disabled ARC, the above error would have been only a warning and you would be allowed to compile.  Of course in both scenarios (with or without ARC) you would crash when running the code.  Here's the warning you'd get with ARC turned off:

Warning: Multiple methods named 'add:' found

If anyone else plays around with this and gets different results than me, I'd be interested in hearing about it.


 on: August 24, 2016, 11:13:48 AM 
Started by blur - Last post by blur
Okay I have made leaps and bounds more progress with Objective-C and iOS programming. I have figuired this out myself. I use two NSArrays with the same number of elements. Then access the array index of the other NSArray [objectAtIndex]. It works geat.

 on: August 24, 2016, 12:22:11 AM 
Started by sampp18 - Last post by sampp18
Hye,I having some problem here please help me as im new to xcode and objective C

#define kBaseURL      @"http://api.pokemon.com/"
I defined ^ on my prefix.pch file

And to make maintenance easier in the future,so By defining kBaseURL = "http://api.pokemon.com/" I wouldnt have to manually edit every single line on my code and just by editing on my prefix page.

1)NSDictionary *dictchat;
        if ([[responseDict objectForKey:@"user_id"] isEqual:[NSNull null]]) {
            dictchat = @{@"UtoB":@"YES", @"user_id":@"1", @"first_name":@"Support", @"last_name":@"Oncalled", @"avatar_url":@"http://api.pokemon.com/images/original/missing.png", @"business_id":[responseDict objectForKey:@"id"], @"business_title":[responseDict objectForKey:@"profile_title"]};

NSString *Name=[NSString stringWithFormat:@"%@",[[self.filteredArray objectAtIndex:[sender tag]] valueForKey:@"company_name"]];
        NSString *Title=[NSString stringWithFormat:@"http://api.pokemon.com/web/promotions/%@",[[self.filteredArray objectAtIndex:[sender tag]] valueForKey:@"id"]];

NSString *tempString;
            if ([self.filteredArray[indexPath.row]valueForKey:@"post_url"]!=nil|| [[self.filteredArray[indexPath.row]valueForKey:@"post_url"] isKindOfClass:[NSNull class]])
                tempString = [[self.filteredArray[indexPath.row]valueForKey:@"post_url"] stringByReplacingOccurrencesOfString:@"http://web.oncalled.com" withString:@""];

How to replace instead of using the link,I replace kBaseURL within the avatar url above,really appreciate helps it so much

Pages: [1] 2 3 ... 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.