Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Passing Objects Between Classes in Cocoa

blackenedheartblackenedheart Posts: 125New Users @ @
How do I accomplish this? Seems simple enough, but I can't seem to share an NSArray between these two different classes I have. It makes me sad :(

Thanks In Advance...

Replies

  • givensurgivensur On the Information SuperhighwayPosts: 541Registered Users @ @ @
    There's a ton of ways. Delegate pattern, NSNotificationCenter, Singletons, persistant storage, etc., etc.

    What have you tried?
    I make cake apps.
  • blackenedheartblackenedheart Posts: 125New Users @ @
    edited March 2014
    I have an NSArray in one class, and then I need to use it in a new class. I thought it was as simple as importing the class, and then using dot notation, but no it's not simple like PHP!
  • blackenedheartblackenedheart Posts: 125New Users @ @
    edited March 2014
    This is the new class…
    #import <Foundation/Foundation.h>
    #import "fileimport.h"
    
    @interface rotaryaxis : NSObject
    
    @property(nonatomic, assign) NSMutableArray*normals;
    
    @end
    
  • blackenedheartblackenedheart Posts: 125New Users @ @
    edited March 2014
    I was assuming this would work… but it doesn't.
    #import "rotaryaxis.h"
    
    @implementation rotaryaxis
    
    @synthesize normals;
    
    -(void)movearray
    
    {
        fileimport.vertexnormals = normals;
    }
    
    @end
    
  • givensurgivensur On the Information SuperhighwayPosts: 541Registered Users @ @ @
    If you have an instance of an object, and it has a public property, then you can access that property using dot notation.

    Importing a file header is not how you get an instance of an object.

    I'm guessing, you may not know what an instance of an object is. If that is the case, then you'll want to go read some introductory tutorials and or a good introductory book on Object Oriented Programming concepts in Objective-C.
    I make cake apps.
  • blackenedheartblackenedheart Posts: 125New Users @ @
    Can you clarify how to make an object public? From what I understand, it's more complicated than that.
  • blackenedheartblackenedheart Posts: 125New Users @ @
    Also, @public is highly discouraged so maybe it's you that needs to buy a "good introductory book on Objective-C"… Comments like that are pretty useless…
  • givensurgivensur On the Information SuperhighwayPosts: 541Registered Users @ @ @
    edited March 2014
    Sorry, most Cocoa developers would realize that when I say "public" property that I mean a property declared in the header file, rather than in the class extension in the implementation file.

    Then again, most Cocoa developers would also have some sort of understanding about object instances, so I guess it's my fault for assuming you'd be able to follow along with what I was saying.

    Edit: The funny thing is, I reworded the suggestion about you reading a book or a tutorial like five times, because I didn't want it to sound condescending. You really are a beginner though. I'm sorry if you don't want to believe that, but this is first-day of programming in Objective-C type knowledge that you are confused about.
    I make cake apps.
  • blackenedheartblackenedheart Posts: 125New Users @ @
    Thanks for all that great code you posted.
  • givensurgivensur On the Information SuperhighwayPosts: 541Registered Users @ @ @
    Code posted for what? First of all, you haven't even described the situation you're trying to pass data around in. THERE'S TONS OF WAYS TO PASS DATA IN OBJECTIVE-C! Read up on some of the different ways I posted in the very first answer in this thread.

    I am not going to write code for you to show you every single way when you don't yet understand what an instance of an object is. I'm beginning to think you are just a troll account, so I guess I should stop feeding you.
    I make cake apps.
  • themathministerthemathminister Posts: 81Registered Users @
    Which object instantiates the other objects? That's where you can pass the reference to the other object. Then you can access the "public" properties.
Sign In or Register to comment.