Amazon.com Widgets Program 15-12 @selector question
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 20, 2013, 01:01:42 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Chapter Study
| | |-+  Chapter 15 - Numbers, Strings, and Collections
| | | |-+  Program 15-12 @selector question
Pages: [1]   Go Down
Print
Author Topic: Program 15-12 @selector question  (Read 406 times)
Wikiboo
Newbie
*
Posts: 1


Email




« on: May 12, 2011, 04:16:17 AM »

I've got stuck on:

Code: (Objective-C)
-(void) sort
{
[book sortUsingSelector: @selector(compareNames:)];
}

I don't really understand what selector is?

I've read chapter 9 again, but it's not very clear to me yet.
Can someone explain to me in some basic example what selector is and what function does it have?
And what does it do in Program 15-12?
Logged
skochan
Administrator
Hero Member
*****
Posts: 3109







« Reply #1 on: May 12, 2011, 01:31:43 PM »

In order to pass a reference to a method (compareNames:) as an argument to another method (sortUsingSelector:) you need to convert the method name into what's called a "signature" (it's type is SEL).  The @selector directive does this conversion for you. 

Hope this helps.

Cheers,

Steve
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.