如何在不使用 extern 的情况下访问另一个类中声明的变量?

发布于 2024-09-01 03:31:03 字数 219 浏览 2 评论 0原文

我们可以不使用 extern 来访问 classB 中在 classA 中声明的整数类型变量吗?

对于我使用的对象 ClassA *obj1 = [[ClassA alloc]init];并将 A 类的对象访问到 B 类中。

但是,我无法使用 int 、 float 、 NSTimeInterval 来执行它们。在不使用 extern 的情况下我们该如何为他们做呢?

谢谢。

Can we access the integer type variables in classB which are declared in classA by not using extern?

For objects I used ClassA *obj1 = [[ClassA alloc]init]; And accessed the objects of classA into class B.

But, I am not able to do them with the int , float, NSTimeInterval. How can we do for them without using extern ?

Thank You.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪眸﹌ 2024-09-08 03:31:03

我认为你可以在接口中声明它,例如:

@interface NCItem : NSObject {
  @private
    UIImage *image;        
    NSNumber *highestPrice;        
    NSMutableArray *services;
}

@property (nonatomic, retain) UIImage *image;    
@property (nonatomic, retain) NSNumber *highestPrice;

在实现文件中:

@synthesize highestPrice;
@synthesize services;
@synthesize image;

并且你可以在类 B 中使用它:

ClassA *objA = [[ClassA alloc]init];
objA.image

这些都是 OOP 的内容
是什么阻止你这样做?

I think you can just declear it in the interface like:

@interface NCItem : NSObject {
  @private
    UIImage *image;        
    NSNumber *highestPrice;        
    NSMutableArray *services;
}

@property (nonatomic, retain) UIImage *image;    
@property (nonatomic, retain) NSNumber *highestPrice;

and in the implementation file:

@synthesize highestPrice;
@synthesize services;
@synthesize image;

and you can use this in class B:

ClassA *objA = [[ClassA alloc]init];
objA.image

These things are all OOP is about
What is preventing you to do so?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文