需要 Xcode 基本解释

发布于 2024-12-07 06:34:20 字数 1003 浏览 0 评论 0原文

我实际上是 xcode 的新手。我可以自己辨认出一些东西,但对某些东西的作用以及它们为什么放在那里有疑问。我尝试阅读许多电子书,观看教程,但他们从不深入基础知识,总是只是说“添加这个,单击此处等”

有人可以给我一些问题的答案吗? 好吧,我知道 ios 应用程序主要是由视图组成的,视图由控制器控制。每个控制器都有一个头文件(.h)和一个模块?类?文件 (.m)。 .h 文件包含 .m 文件中使用的变量和函数的声明。 整个应用程序由称为“代理”的主“控制器”控制。 .h 文件中的定义可能是操作 IBAction 或 IBLabel 等。

对我来说,提出问题的是这些行:

@class FlipsideViewController;

@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end

@interface FlipsideViewController : UIViewController

@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;

- (IBAction)done:(id)sender;

为什么有时在另一个视图控制器中加载委托类

@class MainViewController;

,以下内容会做什么,这意味着 @interface 声明是什么?

@interface flipAppDelegate : NSObject <UIApplicationDelegate>

很抱歉

nonatomic, retain

提出了非常愚蠢的问题,但每个教程都跳过了这些事情。 我可以遵循 YouTube 视频或手册,但它并没有教给我很多东西......

I am actually a newby at xcode. I can make out a few things be myself but have questions about what some things do and why they are put there. I have tried to read many e-books, watched tutorials, but they never go into the basics, alway just say "Add this, Click here etc"

Could someone give me some answers to a few questions please.
Ok, I know an ios app is mostly made out of Views, views are controlled by controllers. Each controller has a header (.h) file and a module?class? file (.m). The .h file contains the declarations of variables and functions used in the .m file.
The whole app is controlled by a master "controller" called the "delegate".
Definitions in .h file may be for example an action IBAction or IBLabel or something.

What raises questions for me is for example these lines:

@class FlipsideViewController;

@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end

@interface FlipsideViewController : UIViewController

@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;

- (IBAction)done:(id)sender;

and why are sometimes in another view controller the delegate class loaded

@class MainViewController;

what does the following do, meaning what is the @interface declaration?

@interface flipAppDelegate : NSObject <UIApplicationDelegate>

what is

nonatomic, retain

sorry for asking really stupid questions, but every tutorial just skips these things.
I can follow a youtube video or a manual, but it doesn't teach me a lot...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅忆流年 2024-12-14 06:34:20

让我尝试一次一个地回答您的问题。

什么是@interface声明?

接口声明了一个类。通过声明一个类,我的意思是它指定它包含的实例变量和私有/公共方法。同样,头文件仅包含方法的声明,方法的实现/主体位于模块类中。所以,这里——

@interface FlipsideViewController:UIViewController

FlipsideViewController 类派生自 UIViewController/subclasses/extends。 ie 是 UIViewController 的一种,但添加了自己的功能。

同样,

@interface flipAppDelegate : NSObject <UIApplicationDelegate>

子类化 NSObject 并实现 UIApplicationDelegate 协议。协议本质上是类承诺实现的一组方法(尽管可以有可选方法)。

为什么有时在另一个视图控制器中加载委托类

委托模式允许一个类将其工作委托给另一个实现委托协议的类。因此,这里,FlipsideViewController 保留委托对象的一个​​实例,以便可以调用它的 flipsideViewControllerDidFinish:

什么是非原子的,保留

意味着当你为实例变量设置一个值时,该值的引用计数将增加并设置为你的变量。而且,它不会作为原子操作发生。仅在多线程环境中才需要原子性。

@synthesize 只是为变量生成 getter 和 setter 的快捷方式。

Let me try to answer your questions, one at a time.

what is the @interface declaration?

The interface declares a class. By declaring a class, I mean it specifies the instance variables and private/public methods that it contains. Again, the header file only contains the declaration of the methods, and the implementation/body of the methods lies in the module class. So, here-

@interface FlipsideViewController : UIViewController

The class FlipsideViewController derives from/subclasses/extends UIViewController. i.e Is a type of UIViewController but adds its own features.

Similarly

@interface flipAppDelegate : NSObject <UIApplicationDelegate>

Subclasses NSObject and implements the UIApplicationDelegate protocol. A protocol is essentially a set of methods that a class promises to implement (although there can be optional methods).

why are sometimes in another view controller the delegate class loaded

The delegate pattern allows a class to delegate its work to another class that implements the delegate protocol. So, here, FlipsideViewController keeps an instance of the delegate object, so that its flipsideViewControllerDidFinish: can be called.

what is nonatomic, retain

It means that when you set a value to your instance variable, the value's refcount will be incremented and set to your variable. Also, it will not happen as an atomic operation. You need atomic only in a multi-threaded environment.

@synthesize is simply a shortcut to generate getters and setters for your variables.

走过海棠暮 2024-12-14 06:34:20

您确实需要阅读 Objective-C 编程语言。它非常简短,涵盖了架构、概念和语法的基础知识。

简要说明一些细节:

  • @class 指令用于声明类的名称,而不导入其头文件。它经常用在声明协议的.h文件中,因为协议没有实现,它不需要导入其他类(它们的.h文件)的接口。
  • 协议是一种声明类应具有哪些方法和属性以“实现”协议的方法。
  • @interface 在接口文件 (.h) 中用于声明一个类,意思是描述它将具有的方法和属性、它将实现的协议以及它将继承的超类。在您的示例中,该类将被称为 flipAppDelegate,它继承了 NSObject 类的所有方法和属性,并实现了 UIApplicationDelegate协议。
  • 在类 (.m) 文件中,您将定义(使用所有代码)在接口文件中声明的所有方法和属性。您可以包含自己声明的方法和属性以及您实现的协议中的方法和属性。
  • @synthesize 在类实现文件 (.m) 中用于“合成”——即自动创建代码——您在接口 (.h) 中声明的所有属性文件。由于属性通常只需要基本访问器(仅返回当前值的“getter”和仅设置当前值的“setter”),因此使用 @synthesize 是让编译器创建的快捷方式自动为您存储值的变量、getter 方法和 setter 方法。

You really need to read the Objective-C Programming Language from Apple. It's pretty brief, and runs down the basics of the architecture, concepts, and syntax.

To address, briefly, some specifics:

  • The @class directive is used to declare the name of a class without importing it's header file. It is often used in a .h file declaring a protocol, because a protocol has no implementation, it doesn't need to import the interfaces of other classes (their .h files).
  • A protocol is a way of declaring what methods and properties a class should have in order to "implement" the protocol.
  • @interface is used in an interface file (.h) to declare a class, meaning to describe the methods and properties it will have, the protocols it will implement, and the superclasses from which it will inherit. In your example, the class will be called flipAppDelegate, which inherits all of the methods and properties of the NSObject class, and which implements the UIApplicationDelegate protocol.
  • In your class (.m) file, you will define (with all your code) all of the methods and properties that you declared in your interface file. You include the methods and properties you declared yourself, and from the protocols you implement.
  • @synthesize is used in a class implementation file (.m) to "synthesize" --- that is, automatically create the code for --- all the properties you declared in your interface (.h) file. Since properties normally just need basic accessors (a "getter" that just returns the current value, and a "setter" that just sets the current value), using @synthesize is a shortcut to let the compiler create the variable to store the value, the getter method, and the setter method for you automatically.
策马西风 2024-12-14 06:34:20
  • Xcode = 一个 IDE(集成开发环境)
  • Objective-C = 一种语言
  • Cocoa Touch、Media FrameWork、Core FrameWork = 用于 iOS 开发的框架

我强烈建议从学习 Objective-C 开始。至少首先要有入门知识:

https://developer .apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html

这里有大量的Apple 为您可能想在开发者门户上开始的开发者提供了教程和视频。

  • Xcode = An IDE (Integrated Development Environment)
  • Objective-C = A Language
  • Cocoa Touch, Media FrameWork, Core FrameWork = Frameworks used in developing for iOS

I'd highly recommend starting by learning Objective-C. At least with a primer first:

https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html

There's a wealth of tutorials and videos available from Apple for developers you might want to start on the developer portal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文