从另一个类引用静态 NSString * const [英] Referencing a static NSString * const from another class

查看:40
本文介绍了从另一个类引用静态 NSString * const的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 A 班我有这个:

static NSString * const kMyConstant = @"my constant string";

我如何从 B 类引用这个?

How can I reference this from class B?

推荐答案

你应该在标题中extern你的字符串,然后在实现中定义字符串.

You should extern your string in the header, and then define the string in the implementation.

//ClassA.h
extern NSString * const kMyConstant;

//ClassA.m
NSString * const kMyConstant = @"my constant string";

//ClassB.h/m
#import "ClassA.h"

...
    NSLog(@"String Constant: %@", kMyConstant);

这篇关于从另一个类引用静态 NSString * const的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆