iOS开发笔记 1、iOS版本和Objective-C

简介: 最近的iOS开发总算告一段落,了解和学习了不少的内容,抽了一点时间把开发中参考的一些资料和内容汇总一下。 iOS 2007年iPhone发布 2008年iPhone 3G release, 2009年iPhone 3GS.

最近的iOS开发总算告一段落,了解和学习了不少的内容,抽了一点时间把开发中参考的一些资料和内容汇总一下。

iOS

2007年iPhone发布

2008年iPhone 3G release,

2009年iPhone 3GS.

2010 年iPhone 4 and iPad

Each is a 4.7- or 4.8-ounce computing device. Each contains a 620 MHz ARM CPU that has been underclocked to improve battery performance and reduce heat. The iPhone and iPhone 3G each include 128 MB of dynamic RAM (DRAM) and from 4 to 16 GB of Flash memory. The 3GS received an upgrade to 256 MB of RAM as well as a graphics chip enabling it to run OpenGL ES 2.0.

开发时使用的语言推荐是Objective-c

开发工具Xcode Interface Builder

框架库Cocoa

Objective-c

A header (.h) file

a source code (.m) : Objective c实现文件

命名

The names of files that contain Objective-C source code have the .m extension. Files that declare class and category interfaces or that declare protocols have the .h extension typical of header files.

Class, category, and protocol names generally begin with an uppercase letter; the names of methods and instance variables typically begin with a lowercase letter. The names of variables that hold instances usually also begin with lowercase letters.

■ A class can declare methods with the same names as methods in other classes.

■ A class can declare instance variables with the same names as variables in other classes.

■ An instance method can have the same name as a class method.

■ A method can have the same name as an instance variable.

■ Method names beginning with “_” , a single underscore character, are reserved for use by Apple.

[From “The Objective-C Programming Language”]

运行时

The Objective-C language defers as many decisions as it can from compile time and link time to runtime. Whenever possible, it dynamically performs operations such as creating objects and determining what method to invoke. This means that the language requires not just a compiler, but also a runtime system to execute the compiled code. The runtime system acts as a kind of operating system for the Objective-C language

有些类似动态语言

id

This is the general type for any kind of object regardless of class, and can be used for both instances of a class and class objects themselves.

nil表示一个空对象,即id=0。

在objc/objc.h头文件可以看到id的定义就是个指针

和C#中的Object类似

 

消息

[receiver message];

[receiver message:argument];

[receiver message:arg1 label2:arg2 label3:arg3];

[[UITextView alloc] initWithFrame:textFieldFrame];

 

All your message calls should follow one of these four patterns when naming its receiver: they can call something by its class name (for a class method), by its instance name (for an instance method), by the self keyword, or by the super keyword.

selector

In Objective-C, “selector” has two meanings. It can be used to refer simply to the name of a method when it’s used in a source-code message to an object. It also, though, refers to the unique identifier that replaces the name when the source code is compiled. Compiled selectors are of type SEL. All methods with the same name have the same selector. You can use a selector to invoke a method on an object—this provides the basis for the implementation of the target-action design pattern in Cocoa.

 

SEL setWidthHeight;

setWidthHeight = @selector(setWidth:height:);

setWidthHeight = NSSelectorFromString(aBuffer);

[friend performSelector:@selector(gossipAbout:) withObject:aNeighbor];

is equivalent to:

[friend gossipAbout:aNeighbor];

 

if ( [anObject respondsToSelector:@selector(setOrigin::)] )

[anObject setOrigin:0.0 :0.0];

else

fprintf(stderr, "%s can’t be placed\n",

[NSStringFromClass([anObject class]) UTF8String]);

/* AppleTree.h */

@interface AppleTree : UrTree

{ NSString *appleType;

}

@property NSString *appleType;

- (id)growFruit:(NSString *)appleColor;

@end

/* AppleTree.m */

#import "AppleTree.h"

#import "Apple.h"

@implementation AppleTree

@synthesize appleType;

- (id)growFruit:(NSString *)appleColor

{

Apple *fruit = [Apple appleWithColor:appleColor];

return fruit;

}

@end

 

Categories are used if you want to add behavior to a class without subclassing. As usual, you do so by creating a new pair of files containing @interface and @implementation code. This time, you no longer need to worry about the superclass name but must include a category name in parentheses, as follows:

 

@interface AppleTree (MyAppleChanges)

@implementation AppleTree (MyAppleChanges)

 

As a result, the categorized methods and variables that you describe for the classes are added to the core class definition in your program.

 

A protocol is effectively an interface that’s not tied to a class. It declares a set of methods, listing their arguments and their returns. Classes can then state that they’re using the protocol in their own @interface statements. For example, if you had a Growing protocol that was used by plants and animals alike, you could define its usage as follows:

@interface AppleTree : UrTree <Growing>

The AppleTree class would thus be promising that it would respond to all the methods defined in the Growing protocol.

 

变量和访问修饰符

@interface Worker : NSObject

{

char *name;

@private

int age;

char *evaluation;

@protected

id job;

float wage;

@public

id boss

}

默认是@ protected

Property

@property(attributes) type name;

@property float value;

等同于

- (float)value;

- (void)setValue:(float)newValue;

指示编译器生成访问方法

@synthesize value;

@synthesize firstName, lastName, age = yearsOld;

方法

+ 类方法

- 实例方法

+ (id)alloc

{

...

}

- (BOOL)isFilled

{

...

}

- (void)setFilled:(BOOL)flag

{

...

}

相关文章
|
27天前
|
开发框架 前端开发 Android开发
安卓与iOS开发中的跨平台策略
在移动应用开发的战场上,安卓和iOS两大阵营各据一方。随着技术的演进,跨平台开发框架成为开发者的新宠,旨在实现一次编码、多平台部署的梦想。本文将探讨跨平台开发的优势与挑战,并分享实用的开发技巧,帮助开发者在安卓和iOS的世界中游刃有余。
|
4天前
|
iOS开发 开发者 MacOS
深入探索iOS开发中的SwiftUI框架
【10月更文挑战第21天】 本文将带领读者深入了解Apple最新推出的SwiftUI框架,这一革命性的用户界面构建工具为iOS开发者提供了一种声明式、高效且直观的方式来创建复杂的用户界面。通过分析SwiftUI的核心概念、主要特性以及在实际项目中的应用示例,我们将展示如何利用SwiftUI简化UI代码,提高开发效率,并保持应用程序的高性能和响应性。无论你是iOS开发的新手还是有经验的开发者,本文都将为你提供宝贵的见解和实用的指导。
85 66
|
14天前
|
开发框架 Android开发 iOS开发
安卓与iOS开发中的跨平台策略:一次编码,多平台部署
在移动应用开发的广阔天地中,安卓和iOS两大阵营各占一方。随着技术的发展,跨平台开发框架应运而生,它们承诺着“一次编码,到处运行”的便捷。本文将深入探讨跨平台开发的现状、挑战以及未来趋势,同时通过代码示例揭示跨平台工具的实际运用。
|
19天前
|
Java 调度 Android开发
安卓与iOS开发中的线程管理差异解析
在移动应用开发的广阔天地中,安卓和iOS两大平台各自拥有独特的魅力。如同东西方文化的差异,它们在处理多线程任务时也展现出不同的哲学。本文将带你穿梭于这两个平台之间,比较它们在线程管理上的核心理念、实现方式及性能考量,助你成为跨平台的编程高手。
|
20天前
|
存储 前端开发 Swift
探索iOS开发:从新手到专家的旅程
本文将带您领略iOS开发的奇妙之旅,从基础概念的理解到高级技巧的掌握,逐步深入iOS的世界。文章不仅分享技术知识,还鼓励读者在编程之路上保持好奇心和创新精神,实现个人成长与技术突破。
|
23天前
|
安全 IDE Swift
探索iOS开发之旅:从初学者到专家
在这篇文章中,我们将一起踏上iOS开发的旅程,从基础概念的理解到深入掌握核心技术。无论你是编程新手还是希望提升技能的开发者,这里都有你需要的指南和启示。我们将通过实际案例和代码示例,展示如何构建一个功能齐全的iOS应用。准备好了吗?让我们一起开始吧!
|
29天前
|
安全 Swift iOS开发
Swift 与 UIKit 在 iOS 应用界面开发中的关键技术和实践方法
本文深入探讨了 Swift 与 UIKit 在 iOS 应用界面开发中的关键技术和实践方法。Swift 以其简洁、高效和类型安全的特点,结合 UIKit 丰富的组件和功能,为开发者提供了强大的工具。文章从 Swift 的语法优势、类型安全、编程模型以及与 UIKit 的集成,到 UIKit 的主要组件和功能,再到构建界面的实践技巧和实际案例分析,全面介绍了如何利用这些技术创建高质量的用户界面。
29 2
|
1月前
|
安全 数据处理 Swift
深入探索iOS开发中的Swift语言特性
本文旨在为开发者提供对Swift语言在iOS平台开发的深度理解,涵盖从基础语法到高级特性的全面分析。通过具体案例和代码示例,揭示Swift如何简化编程过程、提高代码效率,并促进iOS应用的创新。文章不仅适合初学者作为入门指南,也适合有经验的开发者深化对Swift语言的认识。
48 9
|
1月前
|
vr&ar Android开发 iOS开发
安卓与iOS开发中的用户界面设计原则
【10月更文挑战第41天】探索移动应用开发的精髓,本文将深入分析安卓和iOS平台上用户界面设计的核心原则。通过比较两大操作系统的设计哲学,我们将揭示如何打造直观、易用且美观的应用程序界面。无论你是初学者还是资深开发者,这篇文章都将为你提供宝贵的见解和实用的技巧,帮助你在竞争激烈的应用市场中脱颖而出。
|
1月前
|
设计模式 Swift iOS开发
探索iOS开发:从基础到高级,打造你的第一款App
【10月更文挑战第40天】在这个数字时代,掌握移动应用开发已成为许多技术爱好者的梦想。本文将带你走进iOS开发的世界,从最基础的概念出发,逐步深入到高级功能实现,最终指导你完成自己的第一款App。无论你是编程新手还是有志于扩展技能的开发者,这篇文章都将为你提供一条清晰的学习路径。让我们一起开始这段旅程吧!