iOS - 创建“实用程序”所有控制器都可以调用的类
问题说明
我是iOS和obective-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?
谢谢,
Alex
Thanks, Alex
正确答案
只需创建一个名为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
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhccjeik
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20