/******by garcon1986********/
int 整型
float 单精度
long 常整型
double 双精度
为什么编译器程序要求声明变量类型?这是因为计算
机程序需要占用部分内存。编译器程序要为每个变量预留出内存空间。不同的数据类型,也就是int型和float型,需要不同的存储空间和代码,编译器程序要预留出足够的空间并使用正确的代码。
% 取余只对整数有效
main() 主函数是程序执行的起点
并不是所有的函数都会
返回一个数值。如果一个函数不返回结果,那么它应该被定义为“void”。“return”语句就成了可选的
函数声明
float
circleArea(float theRadius); // function declaration
int main(){
/**/}
float circleArea(float theRadius) // [10.13]
{ /*函数体*/}
函数中的代码只在函数中有效。这是Objective-C的一个重要特点。
反斜杠“/”叫做转意字符(escape character)
如果希望编写的程序也能在Terminal上运行,需要你确保工程的名称只有一个单词组成,习惯上还不可以使用大写字母。而为图形界面编写的程序的名字一般以大写字母开头。
iphone application demo link:
http://itunes.apple.com/us/app/servicemagic-home-improvement/id326666113?mt=8
=
= 等于
> = 大于等于
> 大于
< = 小于等于
< 小于
! = 不等于
&&
与
|| 或
在Objective-C语言中,真和假分别以1和0代替。它们属于一个特殊的数值类型——布尔型数值
(BOOL)。“真”可以用1或者YES代替;“假”可以用0或者“NO”代替。
Objective-C语言把抽象的概念当作对象。
.h
file and .m file:
The file that ends in ".h" is the Header or
Interface file for the class.
The one that ends in ".m" is the Main
or Implementation file for the class.
The Application Delegate
class that is included with every new Cocoa application.
最主要的类:
King
of the hill, among classes, is the class named NSObject
. Nearly all the classes you will
ever create or use will be subclasses of NSObject
, directly or indirectly.
By
convention, all class names begin with one or more capital letters, and
they may not contain any spaces.
Once you start writing your own
applications, we recommend that you choose a two or three letter prefix
that you'll use for all your classes in order to avoid confusion with
existing class names.
However, don't use NS, as this may confuse you
later on. NS is reserved for Apple's classes. It stands for NeXTStep,
NeXTStep being the operating system Mac OS X was based on when Apple
bought NeXT, Inc.
防止类命名冲突的列表:http://www.cocoadev.com/index.pl?ChooseYourOwnPrefix
select
the Identity button in the Inspector palette (Cmd-6)
Remember:
object instances themselves don't contain the code to perform the
action, but the classes do.
#import <Foundation/Foundation.h>
The
former is for non-GUI apps,
#import <cocoa/cocoa.h>
the latter for
GUI-apps.
处于支配地位的是类NSObject
-(
void
)
setIntValue:(
int
)
anInt
)
In Objective-C, the minus sign marks the beginning of an instance
method declaration (as opposed to a class method declaration, which
we'll talk about later). void
indicates that nothing is returned to the invoker of the method. That
is, when we send a setIntValue:
message
to textField
, our MAFoo
object does not receive a value back from the text
field object. That is ok. After the colon, (
int
)
indicates that the variable anInt
must
be an integer. In our example, we send it a value of 5
or 0
, which are integers, so we are fine.
Accessors
Setter
在函数和方法中的所有变量只在这个函数和方法中有效
polymorphism 多态: 方法在类中是唯一的,不同的类可以有不同的方法名;
“基
本工具”(Foundation Kit)提供了大部分与非图形界面编程相关的服务。另外一个架构被称做“应用程序工具”(Application
Kit),用于处理图形界面编程的各种对象。
All the information for the window is
stored in a nib
file (nib stands for NeXT Interface Builder).
awakeFromNib
:When the window is opened, the awakeFromNib
method is called automatically.
A pointer is simply a variable
that contains the address
of another variable.
指针存储变量的地址;指针本身也是一个变量;
使用&来引用变量的地址;而不是变量的值。
这个地址是在内存中的一个数字;指示出变量的位置。
when the computer evaluates the expression &x
, it returns the address of the
variable x
, not the value stored there.
The address is a number that denotes a specific place in the memory of
the computer (like a room number denotes a specific room in a hotel).
由
类NSString创建的字符串被叫做固定字符串,因为它不可修改。
in Objective-C, objects are
never manipulated directly, but always through pointers to them.
Objects
are always manipulated through pointers
Multiple
variables can reference the same object
The way to make instance
variables available is to create a pair of methods to access and modify
the instance variable. The methods are collectively known as accessor
methods
.
Because methods and variables have separate namespaces
,
no conflict would arise.
Essentially, properties
synthesize accessors directly, using the most efficient and appropriate
memory management.
启动garbage collection:Garbage collection is
needs to be enabled, as it is off by default in a new Xcode project. To
enable it, select your Target app from the Source list, and open the
Inspector. Put a tick next to the "Enable Objective-C Garbage
Collection" item.
ojbect的增加和释放:
[
anObject release]
;
[
anObject release]
;
自动释放:
[
anObject autorelease]
;
Whereas
the Cocoa frameworks
are designed for application development
for Mac OS X desktop and notebook computers, the Cocoa Touch
frameworks
are for applications targeted for the iPhone and iTouch.
Both
Cocoa and Cocoa Touch have the Foundation framework in common. However,
the UIKit
replaces the AppKit
framework under Cocoa
Touch, providing support for many of the same types of objects, such as
windows, views, buttons, text fields, and so on.
Bundle:包含可执行程序和相关资源的文件夹。
程序,框架,插件等软件都是bundle。
Iphone OS中,只有程序能被第三方开发。
nib文件:interface builder文件。 使用loadNibNamed:owner或thereof来load文件。
info.plist包含运行时配置文件(information property list)
本地化文件放在en.lproj 或fr.lproj等之中。
Objective-C 是ANSI C的扩展语言,它面向对象,是cocoa编程的native语言。
类至少包括两部分: 公开的接口和私有的实现。
interface通常有.h后缀(header头文件)
implementation通常有.m后缀(包含源代码)
这两者类似于c语言的 math.h 和math.c 文件。
protocol声明了一个人和类可以实现的接口。
cmd + R 来运行程序,相当于windows的f5
一般c程序通过gcc编译。
gcc test.c -o test 将编译出一个叫test的程序。 -o用来指定程序名字
一般情况下,如果一个程序在mac os x编译好,不能再linux中直接运行,需要重新编译。
scripting语言中, 变量$variable = 2; 而在C语言中需要声明, int variable = 2;
如何在xcode中show line numbers? xcode preferences -> text editing -> show line number
分享到:
相关推荐
Objective-c学习笔记 Objective-c学习笔记
这意味着Objective-C语言不仅需要一个编译器,同时也需要一个运行时系统来执行编译好的代码。这儿的运行时系统扮演的角色类似于Objective-C语言的操作系统,Objective-C基于该系统来工作。本文档将具体介绍NSObject类...
Objective-C 学习笔记 IOS软件开发
这意味着Objective-C语言不仅需要一个编译器,还需要一个运行时系统来执行编译的代码。Runtime系统是一种用于Objective-C语言的操作系统,它使OC语言工作起来。 Runtime的核心是在运行时动态操作类和消息分发给...
这篇笔记主要介绍了Objective-C的一些基础知识,包括以下几个方面: 1. Objective-C概述,介绍了Objective-C的来源、发展历史和作为面向对象的C语言的特点。 2. 第一个OC程序,讲解了如何创建一个OC项目,解释了一些OC...
objective语言快速入门的绝佳途径,是视频教程的完整ppt课件,涵盖所有知识点,后出版书目为《iphone与ipad》开发实战的前半部分语言学习!
《objective-c程序设计》通过大量的实例系统地介绍了objective-c语言的基本概念、语法规则、框架、类库及开发环境。读者在阅读《objective-c程序设计》后,可以掌握objective-c语言的基本内容,并进行实际的iphone/...
希望这个简单的Objective-C语言教程能够为你提供一个入门的起点。Objective-C是一种面向对象的编程语言,广泛应用于Mac OS和iOS开发。通过学习Objective-C的基本语法、类和对象、控制流程和方法等内容,你将能够编写...
C语言主要知识点巩固(学习Objective-C 的前提),PPT格式。
《Objective-C 程序设计(第4版)》作者假设读者没有面向对象程序语言或者C语言(Objective-C基础)编程经验,因此,初学者和有经验的程序员都可以使用这本《Objective-C 程序设计(第4版)》学习Objective-C。...
用Objective-C语言实现了各种设计模式,收集各种例子,方便大家学习和普及设计模式。.zip用Objective-C语言实现了各种设计模式,收集各种例子,方便大家学习和普及设计模式。.zip用Objective-C语言实现了各种设计...
Objective-C 基础教程,从入门到精通 Objective-C 基础教程,从入门到精通,是你学习 Objective-C 的经典之作。
Effective Objective-C是本学习Objective-C的好书,没有见pdf版,亚马逊上的这儿本书的价格不菲。让我们来看看书里的内容和完整的学习笔记吧。
Objective-C 是苹果公司采用的主要编程语言之一,也是开发 macOS 和 iOS 应用程序的主要语言之一。Objective-C 是一种强大而灵活的编程语言,它结合了 C 语言的性能和灵活性以及面向对象编程的特性。本教程提供了 ...
中文名: Objective-C基础教程 作者: Mark Dalrymple Scott Knaster译者: 高朝勤 杨越 刘霞图书 分类: 软件 资源格式: PDF 版本: 扫描版 出版社: 人民邮电出版社 书号: ISBN: 9787115208774 发行时间: 2009...
elcome to Learn Objective- C on the Mac! This book is designed to teach you the basics of the Objective- C language. Objective- C is a superset of C and is the language used by many (if not most) ...
在windows系统下搭建Objective-C开发环境,由于公司要做iphone开发,个人学习objc(Objective-C)语法,所以在windows7下搭建了一个objc开发环境,现把自己整理的帮助文档拿来与大家分享,希望能对大家有所帮助。...
Objective-C是创建Mac OS应用和iPhone应用的主要语言,优雅的面向对象编程环境与C语言特性珠联璧合,造就了它的不俗表现。 本书全面而系统地讲述Objective-C语言的基础知识和面向对象编程的重要概念,结合实例...
objective-c基础学习 资料 适合初学者学习使用
这是一个基于Objective-C语言的基础案例集 旨在用于给初学者快速了解Objective-C语言的语法 .zip