开发者

objective-C syntax beginner question

开发者 https://www.devze.com 2022-12-14 13:13 出处:网络
what is the syntax to use an object (NSString) that declared in another class? object w开发者_如何学GoorkId in class works, i want to use it\'s value in class jobs.

what is the syntax to use an object (NSString) that declared in another class?

object w开发者_如何学GoorkId in class works, i want to use it's value in class jobs.

thanks.


Go here: http://www.cocoadevcentral.com/d/learn_objectivec/

And scroll down to the "Properties" section.


if you declared workId as a property and synthesized it, you should be able to access it using works.workId or [works workId]

http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html


If you'd like to hold a pointer to the same object you can declare a second property in the Jobs class using 'assign' or 'retain', if you'd just like a copy you could declare the property using 'copy'.

@property(nonatomic, copy) NSString* theString;

If Jobs has a pointer to Works like so:

@interface Jobs 
{
    Works* works;
}
@property (nonatomic, retain) Works* works;
@end

You could just use self.works.workId to access the work id from within an instance of the Jobs class.

Could you let us know a little more about your particular use case, it would help to determine what you should be doing.


in Person.h:

#import <Foundation/Foundation.h>

@interface Person : NSObject {
    NSString * name;
}
@end

in Person.m:

@implementation Person

- (NSString*) name {
    return name;
}

- (void)setName:(NSString *)aName {
    [name autorelease];
    name = [aName copy];
}

@end
0

精彩评论

暂无评论...
验证码 换一张
取 消