- 浏览: 239562 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (118)
- Ruby/ROR (4)
- Mac (28)
- 我的见闻触发你我的灵感 (1)
- 创业 (1)
- JOSSO (2)
- XML (2)
- OpenRemote (1)
- 娱乐 (2)
- 版权/License (1)
- Java/Spring (4)
- 调试 (1)
- 路由器 (2)
- 技术博客 (21)
- 虚拟机 (1)
- Javascript (6)
- SVN (2)
- HA(Home Automation) (0)
- Android (2)
- iPhone/iPod (23)
- iPad (22)
- iOS公共 (28)
- Windows7 (1)
- 服务器技术 (2)
- 其它 (1)
- Shell (1)
- 数据库 (1)
- 问题总结 (1)
最新评论
-
zjjzmw1:
...
转载:IOS开发之——objectForKey与valueForKey在NSDictionary中的差异 -
hldfxh:
解决了我的问题
JSON Lib, XML转JSON字符串不要namespace,以及处理特殊xml属性"type" -
herry68:
可以给我提供以下你的这个NSData+Base64.h类吗
图片转base64串及反转回图片 -
herry68:
我用这个方法把图片转换成nsstring成功了,但是从nsst ...
图片转base64串及反转回图片 -
hibluse:
handy.wang 写道hibluse 写道我已经设置了WA ...
基于FMDB-SQLite的App数据库性能优化
Referenced from: http://developer.apple.com/mac/library/referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/index.html#//apple_ref/doc/uid/TP40007594
=====================================================
Learning Objective-C: A Primer
- Table of Contents
Learning Objective-C: A PrimerThe Objective-C language is a simple computer language designed to enable sophisticated object-oriented programming. Objective-C extends the standard ANSI C language by providing syntax for defining classes, and methods, as well as other constructs that promote dynamic extension of classes. (This document doesn’t attempt to teach any aspects of C itself. If you’re not familiar with the language, you should learn about the basics before you proceed.) If you have programmed with object-oriented languages before, the following information should help you learn the basic syntax of Objective-C. Many of the traditional object-oriented concepts, such as encapsulation, inheritance, and polymorphism, are all present in Objective-C. There are a few important differences, but those differences are called out in this article and more detailed information is available if you need it. If you have never programmed using an object-oriented language before, you need to have at least a basic understanding of the associated concepts before proceeding. The use of objects and object-oriented design patterns is fundamental to the design of Cocoa applications, and understanding how they interact is critical to creating your applications. For an overview of concepts, see Object-Oriented Programming with Objective-C . In addition, see Cocoa Fundamentals Guide for information about the design patterns used in Cocoa. For full details of the Objective-C language and syntax, see The Objective-C Programming Language . Objective-C: A Superset of CObjective-C is a superset of the ANSI version of the C programming language and supports the same basic syntax as C. As with C code, you define header files and source files to separate public declarations from the implementation details of your code. Objective-C header files use the file extensions listed in Table 1 .
When you want to include header files in your source code, you typically use a ClassesAs in most other object-oriented languages, classes in Objective-C provide the basic construct for encapsulating some data with the actions that operate on that data. An object is a runtime instance of a class, and contains its own in-memory copy of the instance variables declared by that class and pointers to the methods of the class. The
specification of a class in Objective-C requires two distinct pieces:
the interface and the implementation. The interface portion contains
the class declaration and defines the instance variables and methods
associated with the class. The interface is usually in a Figure 1
shows the syntax for declaring a class called Figure 1 A class declaration
Note:
Although
this class declaration declares only methods, classes can also declare
properties. For more information on properties, see “Declared Properties”
.
When
storing objects in variables, you always use a pointer type.
Objective-C supports both strong and weak typing for variables
containing objects. Strongly typed pointers include the class name in
the variable type declaration. Weakly typed pointers use the type The following example shows strongly and weakly typed variable declarations:
Notice the Methods and MessagingA class in Objective-C can declare two types of methods: instance methods and class methods. An instance method is a method whose execution is scoped to a particular instance of the class. In other words, before you call an instance method, you must first create an instance of the class. Class methods, by comparison, do not require you to create an instance, but more on that later. The declaration of a method
consists of the method type identifier, a return type, one or more
signature keywords, and the parameter type and name information. Figure 2
shows the declaration of the Figure 2 Method declaration syntax This declaration is preceded by a minus ( When you want to call a method, you do so by messaging an object. A message is the method signature, along with the parameter information the method needs. All messages you send to an object are dispatched dynamically, thus facilitating the polymorphic behavior of Objective-C classes. Messages are enclosed by brackets (
To
avoid declaring numerous local variables to store temporary results,
Objective-C lets you nest messages. The return value from each nested
message is used as a parameter, or as the target, of another message.
For example, you could replace any of the variables used in the
previous example with messages to retrieve the values. Thus, if you had
another object called
Objective-C also provides a dot syntax for invoking accessor methods
. Accessor methods get and set the state of an object, and typically take the form
You can also use dot syntax for assignment:
This is simply a different syntax for writing, Although the preceding examples sent messages to an instance of a class, you can also send messages to the class itself. When messaging a class, the method you specify must be defined as a class method instead of an instance method. You can think of class methods as something akin to (but not exactly like) static members in a C++ class. You typically use class methods as factory methods to create new instances of the class or for accessing some piece of shared information associated with the class. The syntax for a class method declaration is identical to that of an instance method, with one exception. Instead of using a minus sign for the method type identifier, you use a plus (+) sign. The following example illustrates how you use a class method as a factory method for a class. In this case, the
Listing 1
shows the implementation of Listing 1 A class implementation
Declared PropertiesDeclared properties are a convenience notation used to replace the declaration and, optionally, implementation of accessor methods. You include property declarations with the method declarations in your class interface. The basic definition uses the
Each
readable property specifies a method with the same name as the
property. Each writable property specifies an additional method of the
form In your class implementation, you can use the
You can combine the
Practically speaking, properties reduce the amount of redundant code you have to write. Because most accessor methods are implemented in similar ways, properties eliminate the need to implement a getter and setter method for each property exposed in the class. Instead, you specify the behavior you want using the property declaration and then synthesize actual getter and setter methods based on that declaration at compile time. For information on how to declare properties in your own classes, read Declared Properties in The Objective-C Programming Language . StringsAs
a superset of C, Objective-C supports the same conventions for
specifying strings as C. In other words, single characters are enclosed
by single quotes and strings of characters are surrounded by double
quotes. However, most Objective-C frameworks do not use C-style strings
very often. Instead, most frameworks pass strings around in The
Protocols and DelegatesA protocol declares methods that can be implemented by any class. Protocols are not classes themselves. They simply define an interface that other objects are responsible for implementing. When you implement the methods of a protocol in one of your classes, your class is said to conform to that protocol. Protocols are used frequently to specify the interface for delegate objects. A delegate object is an object that acts on behalf of, or in coordination with, another object. The best way to look at the interplay between protocols, delegates, and other objects is to look at an example. The The declaration of a protocol looks similar to that of a class interface, with the exceptions that protocols do not have a parent class and they do not define instance variables. The following example shows a simple protocol declaration with one method:
In the case of many delegate protocols, adopting a protocol is simply a matter of implementing the methods defined by that protocol. There are some protocols that require you to state explicitly that you support the protocol, and protocols can specify both required and optional methods. As you get further into your development, however, you should spend a little more time learning about protocols and how they are used by reading Protocols in The Objective-C Programming Language . For More InformationThe preceding information was intended primarily to familiarize you with the basics of the Objective-C language. The subjects covered here reflect the language features you are most likely to encounter as you read through the rest of the documentation. These are not the only features of the language though, and you are encouraged to read more about the language in The Objective-C Programming Language . Last updated: 2009-06-25 |
Shop the Apple Online Store (1-800-MY-APPLE), visit an Apple Retail Store , or find a reseller .
Copyright © 2009 Apple Inc. All rights reserved.
<!-- start of path -->
<!-- end of path -->
发表评论
-
Mac OS: bin/cp: Argument list too long
2013-02-27 14:31 2864#解决:Mac OS bin/cp: Argument lis ... -
XCODE4.3.2与真机联调时,console里输出中文乱码
2012-07-19 13:34 1313修改项目的scheme的info,把debugger由LLDB ... -
Mac OS X Lion 显示隐藏目录
2012-03-29 13:28 0在Termminal中输入如下命令。 chflag ... -
Mac OS X Lion 显示隐藏目录
2012-03-29 13:23 1133在Termminal中输入如下命令。 chflags noh ... -
How do I fix NSURLErrorDomain error -999 in iPhone 3.0 OS
2011-01-22 21:58 2334Comment1####################### ... -
iPhone系统常用文件夹位置
2010-11-01 19:49 13221、【/Applications】 91是装在这里 ... -
定制UISlider样式时注意
2010-10-31 15:21 1920只设球(ThumbImage)就会没有track; 不设球就没 ... -
一个鲜为人知的秘密---Using Apache and PHP on Mac OS X
2010-09-28 01:15 1026NOTE: My MAC OS version is 10.6 ... -
Objective-C中的字符串格式化输出
2010-08-19 14:52 1914Objective-C中的字符串格式化输出 %@ ... -
Focus the "Plus+" for iPhone games' development
2010-08-12 12:58 1039location of website: http://plu ... -
ngmoco:) 关注iPhone游戏开发商ngmoco:)
2010-08-12 12:42 1126Website Location: http://www.ng ... -
Is there a better way to handle HTTP error statuses?
2010-05-20 19:04 1479if ([response respondsToSelecto ... -
Install MYSQL in MAC OS X 10.5.8
2010-03-30 16:09 17891)Download MYSQL named mysql-6. ... -
Vertical UISlider in iPhone dev
2010-01-06 20:49 1861Referenced from : http://www.ip ... -
Shell Script Programming
2009-12-19 01:58 980Refrenced from: http://user.it. ... -
Introduction to The Objective-C Programming Language
2009-12-19 01:56 1468Refenced from : http://develope ... -
Introduction to Open Source Scripting on Mac OS X
2009-12-19 01:10 1794From : http://developer.apple.c ... -
Shell tutorial provided by Apple.
2009-12-13 01:33 1000Referenced from http://develope ... -
TextMate Bundle for Git
2009-12-13 01:18 1280The article I referenced from i ... -
Installing git (OSX)
2009-12-11 13:10 1278Installing git (OSX) http ...
相关推荐
Objective-C是苹果公司用于iOS和OS X应用开发的编程语言,由于其与C语言的兼容性以及面向对象的特性,使其成为苹果早期开发者的首选语言。 书中提到了“Developer’s Library”,这是一套专门为编程专业人士设计的...
通过上述分析,可以看出《Programming in Objective-C (4th Edition)》是一本为程序员准备的实用教程,它不仅覆盖了Objective-C语言的基础知识,还结合了Xcode开发工具和iOS 5平台的开发环境,适合初学者和希望提升...
C-Primer-PlusC Primer Plus 5 answers (by PytLab)C Primer Plus(第五版) 编程练习答案(全部本人所写,仅供参考)###Table of Content
总之,《Programming in Objective-C》不仅为初学者提供了一个学习Objective-C语言的平台,也为想要深入了解iOS开发的开发者们提供了一条清晰的学习路径。通过这本书,开发者们能够逐步掌握Objective-C编程基础以及...
综上所述,这本《Programming in Objective-C, 6th Edition》是一本针对苹果操作系统的应用开发者的权威教材,旨在提供Objective-C语言的系统性学习和应用指导。它着重强调了Objective-C编程技能的学习,为开发者...
### Primer-BLAST:NCBI的引物设计与特异性检验工具 #### 一、Primer-BLAST概述 Primer-BLAST是一款由美国国立卫生研究院下属的国家生物技术信息中心(NCBI)开发的在线工具,专门用于设计特异性寡核苷酸引物,...
Primer 5答案(C ++ 11/14) 编译器推荐 Windows:Visual Studio 2015+ Linux:g ++ 5.0以上 g++ -std=c++14 some_ex.cpp -o some_ex Mac:clang ++ 3.7+ clang++ -std=c++1y some_ex.cpp -o some_ex 内容 第一部分...
标题 "Pr-ctica-5--SGE:Primer acercamiento a python trabajando con ficheros" 暗示这是一个关于使用Python处理文件的基础教程。在这个实践中,我们将深入探讨Python编程语言如何有效地操作文件和目录,这是任何...
primer3-py:简单的寡核苷酸分析和引物设计 Primer3-py是流行的Primer3库的Python抽象API。 目的是为自动化寡核苷酸分析和设计提供一个简单可靠的界面。 常规寡核苷酸分析很简单: >>> import primer3>>> primer3....
,第8、9章最为重要,IO库和容器对于一个程序来说是比较基础的,记得不要在C++中还依然保持C的习惯,使用cout而不是printf()、使用vector而不是内置数组、使用迭代器进行遍历。第10、11章有点基础的看起来不是很难,...
@primer Ember Primer是数据可视化原语(组件)的集合,可以将它们组合在一起以构建雄心勃勃的数据可视化和交互式演示。 Ember Primer由构建和维护, 是易于使用的负载测试平台,可用于任何规模的测试。 底漆有3个...
课后习题是检验学习成果和加深理解的重要环节,而"C-Primer-Exercise"则提供了对这些习题的解答,旨在帮助读者巩固所学知识。 在阅读《C++ Primer 5th Edition》时,与书中的练习题进行互动是非常有益的。这些习题...
C++primerplus 课后习题答案 C++primer plus 是一本非常好的 C++ 教程书籍,旨在帮助初学者和中级程序员快速学习 C++ 编程语言。该书籍提供了详细的讲解、实例代码和练习题,以帮助读者更好地理解 C++ 编程语言的...
《基于Primer Vector理论与Pontryagin最大原理的Matlab火箭弹道优化》 在现代航天工程中,火箭弹道优化是一项至关重要的任务,它涉及到火箭的性能提升、飞行安全以及有效载荷的投放等多个关键因素。本文将深入探讨...