`
chriszeng87
  • 浏览: 732814 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Objective C中message,method和selector等的区别和联系

    博客分类:
  • iOS
iOS 
阅读更多

   selector是方法名,message包括selector和方法的参数,method包括selector和方法的具体实现。

 

以下转自stackoverflow: http://stackoverflow.com/questions/5608476/whats-the-difference-between-a-method-and-a-selector

 

  • Selector - a Selector is the name of a method. You're very familiar with these selectors: alloc,initreleasedictionaryWithObjectsAndKeys:setObject:forKey:, etc. Note that the colon is part of the selector; it's how we identify that this method requires parameters. Also (though it's extremely rare), you can have selectors like this: doFoo:::. This is a method that takes three parameters, and you'd invoke it like [someObject doFoo:arg1 :arg2 :arg3]. There's no requirement that there be letters before each part of the selector components. As I said, this is extremely rare, and you will not find it used in the Cocoa frameworks. You can work with selectors directly in Cocoa. They have the type SELSEL aSelector = @selector(doSomething:) or SEL aSelector = NSSelectorFromString(@"doSomething:");

  • Message - a message is a selector and the arguments you are sending with it. If I say[dictionary setObject:obj forKey:key], then the "message" is the selectorsetObject:forKey: plus the arguments obj and key. Messages can be encapsulated in anNSInvocation object for later invocation. Messages are sent to a receiver. (ie, the object that "receives" the message).

  • Method - a method is a combination of a selector and an implementation (and accompanying metadata). The "implementation" is the actual block of code; it's a function pointer (an IMP). An actual method can be retrieved internally using a Method struct (retrievable from the runtime).

 

1
1
分享到:
评论

相关推荐

    Objective-C基础教程源代码 Learn objective-C on the Mac Mark Dalrymple著书

    1. **Objective-C语法**:Objective-C的语法基于C语言,但引入了类、接口和消息传递等概念。这包括定义类、属性(@property)和方法(@selector)的语法,以及理解类接口(.h)和实现(.m)文件的作用。 2. **对象...

    Objective-C基础教程(中文)

    3. 消息(Message):Objective-C中,对象之间的通信通过发送消息实现。消息包含方法名和参数,如`[receiver method:parameter]`。 4. 方法(Method):对象可以响应的消息,由选择器(Selector)和实现...

    Objective-C基础教程彩色版

    - **类(Class)**: 类是Objective-C中的核心概念,它是对象的蓝图,定义了一组属性(ivar)和方法(method)。 - **对象(Object)**: 对象是类的实例,具有特定的属性和行为。 - **消息传递(Message Passing)...

    iOS开发中必备的OC知识

    iOS开发中必备的OC知识涵盖了Objective-C(OC)语言的基础与高级特性,OC是苹果公司主要开发语言之一,用于iOS和Mac OS X应用程序的开发。熟悉OC语言对于从事iOS开发的开发者来说至关重要。 首先,Objective-C是一...

    Object-C资源.docx

    - **与C兼容**:由于它是C语言的扩展,因此可以直接在Objective-C程序中混合使用C代码。 - **动态消息传递**:Objective-C采用动态消息传递机制,这意味着当一个方法被调用时,实际上是向对象发送一条消息。 - **...

    ios runtime动态添加方法demo

    它是一个C语言库,为Objective-C提供了动态特性的支持,如消息传递、动态类型、方法解析等。在iOS应用开发中,熟练掌握Runtime技术能帮助开发者实现很多高级功能,比如KVO(Key-Value Observing)、Category的扩展、...

    object-c学习教程PPT

    Objective-C(Object-C)是苹果公司开发的一种面向对象的编程语言,主要应用于iOS和Mac OS X操作系统。它是C语言的超集,包含了Smalltalk风格的消息传递机制,因此它具有C语言的底层控制能力和Smalltalk的灵活性。在...

    iOS中Runtime的几种基本用法记录

    在iOS开发中,Objective-C的Runtime是一门强大的技术,它提供了在程序运行时对类和对象进行操作的能力。本文将详细介绍Runtime的四种基础用法:消息机制、方法交换、动态加载方法以及消息转发。 1)**消息机制** ...

    ObjCRuntimeGuide

    When a method is called on an object, the Objective-C runtime sends a message to the object, rather than directly invoking the method. This process is abstracted away from the developer and is ...

    runtime原理与使用

    不同于C语言等静态类型语言,在编译阶段就能确定所有函数的调用细节,Objective-C中的函数调用是一种动态过程,即在程序执行时才能确定具体调用哪个函数。 **关键概念**: 1. **动态调用**:Objective-C中的方法...

    ObjC.pdf官方文档

    Objective-C结合了C语言的语法和Smalltalk式的面向对象特性,支持类、对象、消息传递等概念。 #### 二、对象、类与消息传递 **1. 对象与类:** - **对象**是类的一个实例,它具有特定的状态和行为。 - **类**定义...

    ios动态决议

    在iOS开发中,"ios动态决议"是一种关键的特性,它涉及到Objective-C的运行时(runtime)系统。Objective-C是一种面向对象的语言,它的魅力之一就是其强大的动态性,这使得开发者能够在程序运行时进行许多静态语言...

    iOS运行时(runtime)示例代码

    iOS运行时(Runtime)是Apple为其移动操作系统iOS和macOS提供的一种核心技术,它是一个底层的接口,使得开发者能够与Objective-C和Swift等编程语言的运行环境进行交互。在这个环境中,对象、类、方法以及消息传递等...

    ios-一句代码条用一,二,三级选择器.zip

    在iOS开发中,选择器(Selector)是一种非常重要的机制,它允许我们调用对象的方法,而无需显式地创建对象实例。本资源“ios-一句代码条用一,二,三级选择器.zip”可能包含一系列关于如何高效使用一、二、三级选择...

    Runtime 学习详解

    - **消息发送**:Objective-C的对象间通信基于消息传递,`-[receiver message]`实际转化为`objc_msgSend(receiver, selector)`函数调用,Runtime负责查找对应的方法实现并执行。 - **动态方法解析**:Runtime允许...

    ios-Runtime.zip

    iOS中的Runtime系统是苹果开发的一种运行时环境,它在Objective-C和Swift等编程语言中扮演着核心角色。Runtime系统提供了一种方式,让程序在运行过程中可以动态地获取类、对象、方法等信息,甚至可以改变它们的行为...

    forwardingTarget 消息转发.zip

    在Swift编程中,消息转发(Message Forwarding)是Objective-C运行时系统的一个重要特性,它允许我们处理那些未被接收者直接实现的消息。Swift虽然基于更安全的静态类型系统,但仍然支持这一机制,以便在运行时进行...

    ios-interview-train-demo:ios面试火车演示

    Objective-C是C语言的超集,它引入了面向对象的概念,如类、对象、继承、多态等。面试中,面试官通常会考察你对这些基本概念的理解以及实际应用。例如: 1. 类(Class):Objective-C中的所有对象都是类的实例。你...

    IOS Object-C 中Runtime详解及实例代码

    在iOS和macOS开发中,Objective-C的Runtime提供了强大的功能,包括消息传递、动态方法解析、元数据访问等。下面将详细介绍Runtime的一些关键概念和常见用法。 1. **消息传递(Message Dispatch)** Objective-C的...

Global site tag (gtag.js) - Google Analytics