IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 移动开发 -> Apple文档——Programming with Objective-C——Introduction -> 正文阅读

[移动开发]Apple文档——Programming with Objective-C——Introduction

Introduction

ps:斜体表示翻译存在疑问

About Objective-C

关于Objective-C

Objective-C is the primary programming language you use when writing software for OS X and iOS. It’s a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime. Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods. It also adds language-level support for object graph management and object literals while providing dynamic typing and binding, deferring many responsibilities until runtime.

Objective-C是为OS X和iOS系统编写软件的首选语言。它是C语言的超集,在C语言的基础上提供了面向对象功能和动态的runtime机制。Objective-C继承了C语言的语法、原始数据类型、流程控制的同时,又增加了定义类和方法的语法。OC在底层支持类图和对象字面量,并提供动态类型和动态绑定功能,使许多工作得以在运行时进行。

理解:动态的runtime机制、类图、对象字面量、动态类型、动态绑定

At a Glance

概述

This document introduces the Objective-C language and offers extensive examples of its use. You’ll learn how to create your own classes describing custom objects and see how to work with some of the framework classes provided by Cocoa and Cocoa Touch. Although the framework classes are separate from the language, their use is tightly wound into coding with Objective-C and many language-level features rely on behavior offered by these classes.

此文档将介绍OC语言并提供大量的使用实例。你将了解到如何创建类来描述自定义对象,了解到如何使用Cocoa和Cocoa Touch提供的一些框架类工作。虽然这些框架类和OC语言是分离的,但它们的使用与OC的编码紧密相连,许多底层的特性依赖于这些类提供的行为。

理解:Cocoa、Cocoa Touch

An App Is Built from a Network of Objects

应用程序是一组对象的有机结合

When building apps for OS X or iOS, you’ll spend most of your time working with objects. Those objects are instances of Objective-C classes, some of which are provided for you by Cocoa or Cocoa Touch and some of which you’ll write yourself.

为OS X和iOS构建app时,我们将会花费大多数时间在对象上。这些对象是OC类的实例,其中的一部分是由Cocoa和Cocoa Touch提供的,一部分是由自己创建的。

If you’re writing your own class, start by providing a description of the class that details the intended public interface to instances of the class. This interface includes the public properties to encapsulate relevant data, along with a list of methods. Method declarations indicate the messages that an object can receive, and include information about the parameters required whenever the method is called. You’ll also provide a class implementation, which includes the executable code for each method declared in the interface.

如果你在写自己的类,应该从编写描述该类的接口文件开始,其应该显示使用该类的详细信息。 该接口文件应该包含封装数据的属性及方法列表。方法的声明表明了一个对象能够接收到的信息,以及该方法被调用时的参数信息。你也需要提供一个类的实现,包含了每个方法声明的具体实现代码。

Relevant Chapters: Defining Classes, Working with Objects, Encapsulating Data

相关章节:类的定义、使用对象、数据封装

Categories Extend Existing Classes

类别是对现有类的扩展

Rather than creating an entirely new class to provide minor additional capabilities over an existing class, it’s possible to define a category to add custom behavior to an existing class. You can use a category to add methods to any class, including classes for which you don’t have the original implementation source code, such as framework classes like NSString.

可以通过定义一个类别为一个现有的类增加自定义行为,而不必创建一个新的类。可以使用类别为任何的类增加方法,包括没有源代码的类,例如框架中的类NSString。

理解:Category的定义、使用

If you do have the original source code for a class, you can use a class extension to add new properties, or modify the attributes of existing properties. Class extensions are commonly used to hide private behavior for use either within a single source code file, or within the private implementation of a custom framework.

如果拥有类的源代码,那么就可以使用类扩展增加新属性,或者修改现有的类属性。类扩展通常用于隐藏私有属性或方法,要么是在一个源文件中,要么是在自定义的框架中。

理解:类扩展就是category?

Relevant Chapters: Customizing Existing Classes

相关章节:修改现有的类

Protocols Define Messaging Contracts

协议定义了信息发送的规则

The majority of work in an Objective-C app occurs as a result of objects sending messages to each other. Often, these messages are defined by the methods declared explicitly in a class interface. Sometimes, however, it is useful to be able to define a set of related methods that aren’t tied directly to a specific class.

OC的App中的主要工作机制是对象间彼此发送消息。通常,这些消息在类的接口文件中通过方法的声明明确表示出来。然而有时,它也会定义一系列不绑定任何具体类的方法。

Objective-C uses protocols to define a group of related methods, such as the methods an object might call on its delegate, which are either optional or required. Any class can indicate that it adopts a protocol, which means that it must also provide implementations for all of the required methods in the protocol.

OC使用协议定义一组相关的方法,例如一些对象可以委托调用这些方法 ,这些方法可以是必须实现的也可以是可以选择实现的。任何的类都可以表明它遵守某个协议,这意味着它必须实现协议中要求必须实现的方法。

Relevant Chapters: Working with Protocols

相关章节:使用协议

Values and Collections Are Often Represented as Objective-C Objects

数据值和集合通常使用OC对象表示

It’s common in Objective-C to use Cocoa or Cocoa Touch classes to represent values. The NSString class is used for strings of characters, the NSNumber class for different types of numbers such as integer or floating point, and the NSValue class for other values such as C structures. You can also use any of the primitive types defined by the C language, such as int, float or char.

通常,OC使用Cocoa或者Cocoa Touch的类来表示数据值。NSString类用来表示字符串,NSNumber类用来表示不同类型的数例如整形和浮点型,NSValue用来表示其他类型的数据值例如C结构体。你也可以使用C语言定义的原始数据类型,例如整形,浮点型或字符型。

Collections are usually represented as instances of one of the collection classes, such as NSArray, NSSet, or NSDictionary, which are each used to collect other Objective-C objects.

集合通常由集合类的实例表示,例如NSArray,NSSet,或者NSDictionary,他们被用来容纳其它OC对象。

理解:NSSet

Relevant Chapters: Values and Collections

相关章节:数据值和集合

Blocks Simplify Common Tasks

代码块简化通常的任务

Blocks are a language feature introduced to C, Objective-C and C++ to represent a unit of work; they encapsulate a block of code along with captured state, which makes them similar to closures in other programming languages. Blocks are often used to simplify common tasks such as collection enumeration, sorting and testing. They also make it easy to schedule tasks for concurrent or asynchronous execution using technologies like Grand Central Dispatch (GCD).

  移动开发 最新文章
Vue3装载axios和element-ui
android adb cmd
【xcode】Xcode常用快捷键与技巧
Android开发中的线程池使用
Java 和 Android 的 Base64
Android 测试文字编码格式
微信小程序支付
安卓权限记录
知乎之自动养号
【Android Jetpack】DataStore
上一篇文章      下一篇文章      查看所有文章
加:2021-10-15 11:54:32  更:2021-10-15 11:56:40 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/23 22:56:38-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码