简体   繁体   English

与iOS开发相比,Web开发中的模型(MVC)之间有什么区别?

[英]What is the difference between a Model (MVC) in web development compared to iOS development

I come from a Web Development background. 我来自Web开发背景。 I am having trouble understanding how a model is to be used in iOS development. 我无法理解如何在iOS开发中使用模型。

A model in Web Development is a separate file that Controller files access with functions such as getMysqlQueryOf(stuff); Web开发中的模型是一个单独的文件,Controller文件通过getMysqlQueryOf(stuff);等函数进行访问getMysqlQueryOf(stuff);

Does iOS development use the same thing? iOS开发使用相同的东西吗? Should I be creating a MyModel.h and MyModel.m file and including/importing this in all of my View Controllers and accessing the methods inside the model class like that? 我应该创建一个MyModel.h和MyModel.m文件,并在我的所有View控制器中包含/导入它并访问模型类中的方法吗?

Can you show a simple example of a Model class and how it would be accessed from a View Controller? 您能否展示一个Model类的简单示例以及如何从View Controller访问它?

In my iOS experiance, UIViewControllers tend to act as islands unto themselves. 在我的iOS体验中,UIViewControllers倾向于充当自己的岛屿。 The wrong approach is to put everything you would put into a model into the delegate class instead. 错误的方法是将您放入模型的所有内容放入委托类中。 I think your idea of a "Model" is spot on. 我认为你对“模型”的想法很明显。 I would create a someModel.m and a header file and give every class that needs the model a pointer to it and initialize the core model in the delegate. 我将创建一个someModel.m和一个头文件,并为每个需要该模型的类提供指向它的指针,并在委托中初始化核心模型。

IMO, iOS data flow leaves something to be desired. IMO,iOS数据流还有待改进。

If I have a data model that I want to share across various objects, I create it so that I can get access to it statically. 如果我有一个我希望在各种对象之间共享的数据模型,我创建它以便我可以静态访问它。

For example, the code below creates one object dataHandle that can be easily accessed by any other object in the project by including the header file and calling [MyData getMyData]. 例如,下面的代码创建了一个对象dataHandle,通过包含头文件和调用[MyData getMyData],项目中的任何其他对象都可以轻松访问它。

MyData.h MyData.h

@interface MyData : NSObject {
    NSString *dataName; // example data in my object
}
@property (nonatomic, retain) NSString *dataName;
+ (MyData *)getMyData;

MyData.m MyData.m

@implementation MyData
@synthesize dataName;

static MyData *dataHandle;
+ (void)initData
{
    dataHandle = [MyData new];
    [dataHandle setDataName:@"DefaultName"];

}

+ (MyData *)getMyData
{
     if (!dataHandle){
         [MyData initData];
     }
     return dataHandle;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS中的开发和生产SSL证书有什么区别? - What is the difference between development and production SSL certificates in iOS? IOS开发中的协议、扩展和类别有什么区别? 以及如何恰当地使用它们? - What is the difference between protocol, extension and category in IOS development? And how to use them appropriately? IOS开发中的Segue是什么? - What is Segue in IOS development? Development Provisioning Profile 和 Ad Hoc Provisioning Profile 之间有什么区别? - What is the difference between a Development Provisioning Profile and an Ad Hoc Provisioning Profile? iPhone开发 - Origin和bounds有什么区别? - iPhone Development - What's the Difference between the Origin and the bounds? 用于Web开发的iOS Touch ID - iOS Touch ID for Web Development iOS开发的“真正”要求是什么 - What are the *real* requirements for iOS development 开发、生产、开发供应配置文件和分销供应配置文件之间的区别? - Difference between Development, Production, Development Provisioning Profile and Distribution Provisioning Profile? iOS游戏开发的各种框架之间的差异? - diff between various frameworks for iOS game development? 问:iOS开发和部署之间的版本不同 - Q: Different version between Development and Deployment iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM