Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-02-2010, 09:21 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 25
prtfx is on a distinguished road
Default OOP / Import problem: Access to children from super class?

Hi,

I want to have simple messaging between two classes. My problem is, that class TestB (child) already extends class TestA (parent/super class).

Therefore TestB imports TestA.h. So simple so good. But now I want to create a TestB member in TestA ... and I need to import TestB.h in TestA.h

Now the compiler starts complaining ... does anybody know how I can exchange messages between my super-class and its chidren from both sides?

I dont see any bad OOP style here, so it should be possible ...?

Thanks.
prtfx is offline   Reply With Quote
Old 04-02-2010, 10:59 AM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

You have a "loop" in your headers where a includes b includes a. You can break it using the @class directive, which "forward declares" a class.

in A.h:
@class B
in A.m:
#import "B.h"

in B.h:
@class A
in B.m:
#import "A.h"

With the @class directive you don't get any information about the methods or properties of the other object, but you do not need them to compile the header anyway. You usually do need that information when compiling the .m file, though, so the .m file gets the #import.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 04-02-2010, 10:59 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 25
prtfx is on a distinguished road
Default

Ok, got it. I need to refer to the singleton pattern for TestA. Then it works fine, although it was not really what I intended first.
prtfx is offline   Reply With Quote
Old 04-02-2010, 11:01 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 25
prtfx is on a distinguished road
Default

Thanks smasher ... that's exactly what I've searched for.

However, I found that the Singleton fits better to my design. But it's good to know the exact reason why it failed .. fine!
prtfx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 460
14 members and 446 guests
7twenty7, AlanFloyd, David-T, imac74, Jaxen66, logan, lovoyl, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0