我是 iOS 和 obctive-c 的新手,所以我不太清楚如何最好地完成这个看似简单的任务.
I am new to iOS and obective-c so I am not too sure how to best accomplish this seemingly simple task.
我想要的是用伪代码制作一个看起来像这样的类:
What I want is to make a class that looks like this in pseudocode:
class UtilityClass
{
// Have a method that I can pass parameters to
String doCalculation ( String art1 , String arg2 )
{
return arg1 + arg2;
}
}
我的不确定是:
1) xCode 似乎倾向于以相对扁平的方式布置我的文件结构.那么我应该创建一个 utils 目录并将这个文件放在 utils/fileName 下吗?通常我习惯了至少有一些 src 目录,但到目前为止,我还没有被任何东西提示创建一个.2) 如何从我的控制器导入和调用这个类/函数?
1) xCode seems to be inclined to lay out my file structure in a relatively flat way. So should I make a utils directory and have this file be under utils/fileName ? Usually I am kind of used to having at least some src directory, but so far I have not been prompted by anything to create one. 2) How do I import and call this class/function from my controllers?
谢谢,亚历克斯
只需创建一个名为 Utilities 的新组,然后在其中创建您的类.喜欢,
Just create a new group called Utilities, and then create your class inside it. Like,
utils.h
utils.m
稍后在 ViewController 的头文件中添加即可.
Later in your ViewController's header file just add.
#import "utils.h"
如果这个 utils 类被很多控制器在非常胖的项目中使用,那么,找到一个名为的文件,应该在支持文件组内.
if this utils class is used by many controllers in very fat project then, find a file called, Should be inside supporting files group.
YourAppName-Prefix.pch
在那个文件中你有一个这样的代码块,
In that file you have a code block like this,
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#endif
只需编辑此块并在此处添加您的 utils.h
引用,这样您的整个项目就可以创建 utils 对象而无需显式导入到它们自己的标头中.
Just edit this block and add your utils.h
reference here, In this way your entire project can create utils object without explicitly importing into their own header.
像这样编辑,
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "utils.h"
#endif
这篇关于iOS - 如何创建“实用程序"?我的所有控制器都可以调用的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!