Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Has anyone finished assignment three yet? If so would you like to post your code for us to check out?

Cheers,

Tom
 
Hi,

ChOas, would you (or anyone else) mind posting your Controller.h

Whenever I try to compile my (early stages) HelloPoly project I get "error PolygonShape/PolygonShape.h :No such file or directory

I have this line in the Controller.m
#import "PolygonShape.h"


And here is my incomplete Controller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <PolygonShape/PolygonShape.h>

@class PolygonShape;

@interface Controller : NSObject {
IBOutlet UIButton *decreaseButton;
IBOutlet UIButton *increaseButton;
IBOutlet UILabel *numberOfSidesLabel;
IBOutlet PolygonShape *polygon;

}

- (IBAction)decrease;
- (IBAction)increase;
@end


Any help is much appreciated.

regards, Simon

With the same PolygonShape I used this for the Controller implementation of 2b:

Code:
#import "Controller.h"
#import "PolygonShape.h"

@implementation Controller

- (void) updateInterface {
  	numberOfSidesLabel.text = [NSString stringWithFormat:@"%d",polygon.numberOfSides];
}

- (IBAction)decrease:(id)sender {
    NSLog(@"decreasing");
	--polygon.numberOfSides;
	if (polygon.numberOfSides == polygon.minimumNumberOfSides) decreaseButton.enabled = NO;
	increaseButton.enabled = YES;
	[self updateInterface];
}

- (IBAction)increase:(id)sender {
    NSLog(@"increasing");
	++polygon.numberOfSides;
	if (polygon.numberOfSides == polygon.maximumNumberOfSides) increaseButton.enabled = NO;
	decreaseButton.enabled = YES;
	[self updateInterface];
}



- (void) awakeFromNib {
	polygon = [[PolygonShape alloc] initWithNumberOfSides:5 minimumNumberOfSides:3 maximumNumberOfSides:12];	
	NSLog(@"My polygon: %@", polygon);
	[self updateInterface];
}
@end

polygon should be dealloced, I know... Will happen.

also checks before in/de creasing the num of sides would be better as in the future other things might influence the side count.

Oh well...

Hmmm maybe I should go for
Code:
 [polygon setNumberOfSides:polygon.numberOfSides[+-]1]

Is the accessor called when I use the ++ / -- operands ?

[edit]
Ah, it is... sweet.
 
Hi simonjfrancis,

I found that I had to put the full path to my PolygonShape.h file, such as:

#import </Users/Tom/Documents/Assignment 2/PolygonShape.h>

I don't know why - it was in the same directory as my other source files. But anyway that might help.

Tom
 
I think the problem you gusys are having is the mixing of "" and <> around the import of PolygonShape.

As far as I understand the <> will look for the file relative to the library path and "" wil look for the file relative to the current project.

So:
#import </Users/Tom/Documents/Assignment 2/PolygonShape.h>
Wil look in the absolute path as it starts with a /

#import "PolygonShape.h"
will include the .h from your current project directory

#import <PolygonShape/PolygonShape.h>
will start looking for the file in <Library path>/PolygonShape

Simon, if you change
#import <PolygonShape/PolygonShape.h>
to:
#import "PolygonShape.h"

It should work, I think.
 
Thanks for the replies.

I tried changing from #import <> to #import "" but that had no effect.

What ended up working for me was to add a search path to my xcode settings.

In Xcode 3, choose Project > Edit Project Settings to modify your project's build settings (build tab). In the Search Paths collection are settings to add search paths for header files, libraries, and frameworks.
I added /Users/simon/Documents/ (with the recursive option checked) and then it found my header file and compiled (after some other non-compile related issues were resolved).

hope this helps someone else.

regards, Simon
 
@simon: Here is my code thus far:

First is Controller.h
Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"

@interface Controller : NSObject {
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *numberOfSidesLabel;
	IBOutlet PolygonShape *aPolygon;
}
- (IBAction)decrease;
- (IBAction)increase;

@property (nonatomic, retain) UIButton *decreaseButton;
@property (nonatomic, retain) UIButton *increaseButton;
@property (nonatomic, retain) UILabel *numberOfSidesLabel;
@property (nonatomic, retain) PolygonShape *aPolygon;

@end

Here is Controller.m:
Code:
#import "Controller.h"

@implementation Controller
@synthesize numberOfSidesLabel;
@synthesize increaseButton;
@synthesize decreaseButton;
@synthesize aPolygon;

- (IBAction)decrease
{
	--aPolygon.numberOfSides;
	[self updateInterface];
}

- (IBAction)increase
{
	++aPolygon.numberOfSides;
	[self updateInterface];
}

-(void)awakeFromNib
{
	aPolygon = [[PolygonShape alloc] initWithNumberOfSides:numberOfSidesLabel.text.integerValue minimumNumberOfSides:3 maximumNumberOfSides:12];
	NSLog(@"My polygon: %@", [aPolygon polyDescription]);
}

-(void)updateInterface
{
	
	numberOfSidesLabel.text = [NSString stringWithFormat:@"%d", [aPolygon numberOfSides]];
	if (aPolygon.numberOfSides == aPolygon.minimumNumberOfSides)
		{
			decreaseButton.enabled = NO;
		}
	else
		{
			decreaseButton.enabled = YES;
		}
	if (aPolygon.numberOfSides == aPolygon.maximumNumberOfSides)
		{
			increaseButton.enabled = NO;
		}
	else
		{
			increaseButton.enabled = YES;
		}
}


@end
 
@ChOas:

Thanks very much for that, I didn't really know about the " versus the <> thing :)
 
JLatte,

thanks for providing your code. It was very helpful for me to identify a number of issues that were improperly implemented in my code. I also wasn't clear on how the updateInterface method was supposed to be called until I saw your how you did it. It'd be greatly appreciated if you (or others) are willing to continue to post working code.

thanks in advance.

simon
 
Copy

Hi simonjfrancis,

I found that I had to put the full path to my PolygonShape.h file, such as:

#import </Users/Tom/Documents/Assignment 2/PolygonShape.h>

I don't know why - it was in the same directory as my other source files. But anyway that might help.

Tom

You may not have copied the item ... the best way to add files in Xcode is to say the file is on your desktop too then while the Project is open in Xcode to drag that file into classes ... if it is a class file ... then a little menu will drop down saying would you like to copy the file ... You should turn the checkbox on 99% of the time ... then click ok and you will be all set and the #import<file.h> should work fine then
 
@simon: Here is my code thus far:

First is Controller.h
Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"

@interface Controller : NSObject {
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *numberOfSidesLabel;
	IBOutlet PolygonShape *aPolygon;
}
- (IBAction)decrease;
- (IBAction)increase;

@property (nonatomic, retain) UIButton *decreaseButton;
@property (nonatomic, retain) UIButton *increaseButton;
@property (nonatomic, retain) UILabel *numberOfSidesLabel;
@property (nonatomic, retain) PolygonShape *aPolygon;

@end

Here is Controller.m:
Code:
#import "Controller.h"

@implementation Controller
@synthesize numberOfSidesLabel;
@synthesize increaseButton;
@synthesize decreaseButton;
@synthesize aPolygon;

- (IBAction)decrease
{
	--aPolygon.numberOfSides;
	[self updateInterface];
}

- (IBAction)increase
{
	++aPolygon.numberOfSides;
	[self updateInterface];
}

-(void)awakeFromNib
{
	aPolygon = [[PolygonShape alloc] initWithNumberOfSides:numberOfSidesLabel.text.integerValue minimumNumberOfSides:3 maximumNumberOfSides:12];
	NSLog(@"My polygon: %@", [aPolygon polyDescription]);
}

-(void)updateInterface
{
	
	numberOfSidesLabel.text = [NSString stringWithFormat:@"%d", [aPolygon numberOfSides]];
	if (aPolygon.numberOfSides == aPolygon.minimumNumberOfSides)
		{
			decreaseButton.enabled = NO;
		}
	else
		{
			decreaseButton.enabled = YES;
		}
	if (aPolygon.numberOfSides == aPolygon.maximumNumberOfSides)
		{
			increaseButton.enabled = NO;
		}
	else
		{
			increaseButton.enabled = YES;
		}
}


@end

Know of any practical reasons of using -(id) versus -(void) ... is there any benefits to one or the other i usually just use -(void) for my functions that return nothing ... but -(id) works as well ...
 
@thomasjt

try replacing this:
Code:
	for (id obj in myObjects) {
		NSLog(@"Class Name: %@", [obj className]);
		
	}

by this:
Code:
	for (id *obj in myObjects) {
		NSLog(@"Class Name: %@", [obj className]);
		
	}
 
i'm still on 2B
The NSLog message won't load in console. but if I try to change value of the text label as I click "Increase", "Decrease" buttons, the value changed accordingly. so i think my connections are correct, but for some reason NSLog won't work. anybody got this problem? I need to get this fix otherwise I can't debug, test my apps.

Thanks.
 
@ChOas:

Thanks very much for that, I didn't really know about the " versus the <> thing :)

<> is reserve for special system folder, which you won't use unless you are referring to framework. "" is what you should always use.
 
Quick question that has been bugging me for a while since I've watched Evan's lectures:

In xcode, when writing something such as UIBarButtonSystem, what is the key combination to popup the list of possible options? Right now I have it so that I can tab and auto-complete the suggested item but how do I view the list of options? I've checked "Show arguments in pop-up list" under preferences but that didn't seem to help.

Thanks in advance :apple:
 
n/m I found the answer. I guess I wasn't using the best search terms originally. the shortcut by default is set to: control ,
 
I can personally vouch for this course. I knew almost next to nothing about how to begin programming an app and after spending a lot of time with this course I'm about halfway done with my first app now.

Googling around for tutorials wasn't helping -- I needed a structured approach to learning Obj C and for me this class was a huge help.
 
I can personally vouch for this course. I knew almost next to nothing about how to begin programming an app and after spending a lot of time with this course I'm about halfway done with my first app now.

Googling around for tutorials wasn't helping -- I needed a structured approach to learning Obj C and for me this class was a huge help.
How about reading a book, "Beginning iPhone Development" would have taken you further and deeper into most subjects they have discussed in class. The class should only be used as reference, not the main learning source. I am falling asleep through these lectures.
 
I'm having some problems with assignment three.

I have three custom classes: Controller, PolygonShape, and UIPolygonView

In the assignment handouts, Evan says that you need to give your custom UIView class access to your PolygonShape. Does anyone know how to do that?

In the UIPolygonView class I am trying to set up some draw code, but when I try something like

Code:
int sideToDraw = [aPolygonShape numberOfSides]

...I get the familiar 'error: aPolygonShape undeclared (first use in this function).' error message.

I realise it's probably some very basic class knowledge I am lacking here, but how do I let my UIPolyView see the instance of a PolygonShape that I created in my Controller class?

Many thanks for any help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.