本文介绍了如何添加“类前缀";创建xcode项目模板时输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个已经定义过的自定义模板.当我使用该模板时,Xcode不会要求"Class Prefix".因此,使用此模板创建的类都具有一个类名作为项目名,后跟我们提供的类名,如"SampleProjectViewController.h""SampleProjectViewController.m".

在创建新类时,是否可以添加"Class Prefix"字段并使用该类前缀,因此当我创建新类时,预期的类名称为SPViewController.hSPViewController.m吗?

解决方案

com.apple.dt.unit.prefixable添加到祖先中,它将自动添加对话框.然后,使用___VARIABLE_classPrefix:identifier___作为替换字符串.例如.假设您有一个名为Foo的课程:

@interface ___VARIABLE_classPrefix:identifier___Foo : NSObject
@end

@implementation ___VARIABLE_classPrefix:identifier___Foo
@end

文件不需要那么长的前缀,您只需在定义中使用___VARIABLE_classPrefix:identifier___Foo.m作为键,使用Foo.m作为Path(或者您的命名方式)即可./p>

I am using a custom template that was defined already by some one. When I use that template, Xcode is not asking for "Class Prefix". Because of this, what ever the classes that are created using this template are having a class name as project name followed by the class name we are giving like "SampleProjectViewController.h" or "SampleProjectViewController.m".

Is there a way to add "Class Prefix" field and use this class prefix, while creating new classes, so that when I create a new class, expected class name would be SPViewController.h or SPViewController.m ?

解决方案

Add com.apple.dt.unit.prefixable to the Ancestors, it will automatically add the dialog. Then, use ___VARIABLE_classPrefix:identifier___ as a replacement string. Eg. let's say you have a class called Foo:

@interface ___VARIABLE_classPrefix:identifier___Foo : NSObject
@end

@implementation ___VARIABLE_classPrefix:identifier___Foo
@end

Files don't need to have that long prefix, you can simply do that in your Definitions by using something like ___VARIABLE_classPrefix:identifier___Foo.m as the key and Foo.m as the Path (or however your naming works).

这篇关于如何添加“类前缀";创建xcode项目模板时输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 13:36