本文介绍了从另一个类引用静态NSString * const的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在A类中,我有这个:
static NSString * const kMyConstant = @"my constant string";
如何从B类中引用呢?
推荐答案
您应该在标题中替换字符串,然后在实现中定义该字符串.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!