Swift: A function with a Selector argument returns an unmanaged?
What is the use of -
func perform(_ aSelector: Selector!) -> unmanaged<AnyObject>!
in iOS?
- To call a method of a class?
- To add a selector method?
- To add a class delegate?
- To define a class? (I doubt it's this)
I was originally thinking that it it was to add a selector method, but after looking at it some more I think it may be "to call a method of a class." Selectors are used for target/action paradigms where I kick something off and when the event fires or finishes then it wants to fire off some kind of action method.
In this example do I pass it a parameter of a selector function then at the end of this "perform" function, I am returning an unmanaged object of any type? Does that even make sense?
Thanks!
ios swift
add a comment |
What is the use of -
func perform(_ aSelector: Selector!) -> unmanaged<AnyObject>!
in iOS?
- To call a method of a class?
- To add a selector method?
- To add a class delegate?
- To define a class? (I doubt it's this)
I was originally thinking that it it was to add a selector method, but after looking at it some more I think it may be "to call a method of a class." Selectors are used for target/action paradigms where I kick something off and when the event fires or finishes then it wants to fire off some kind of action method.
In this example do I pass it a parameter of a selector function then at the end of this "perform" function, I am returning an unmanaged object of any type? Does that even make sense?
Thanks!
ios swift
Are you referring to the method fromNSObjectProtocol
which is from the Objective-C runtime?
– rmaddy
Nov 14 '18 at 23:41
@rmaddy --> I don't know. This was asked on a quiz that I was taking and I didn't have any other information for this question.
– TSuperman
Nov 14 '18 at 23:49
@rmaddy -> If the method was referring to the NSObjectProtocol, would it have a different meaning or do something that I wouldn't normally expect?
– TSuperman
Nov 15 '18 at 0:01
1
Basically it's something you would very rarely, if ever, use in Swift. It should rarely be used directly any more in Objective-C.
– rmaddy
Nov 15 '18 at 0:03
1
Indeed this used to be forbidden in Swift, and even now should be avoided, as Swift provides better ways. See stackoverflow.com/questions/24158427/… for example
– matt
Nov 15 '18 at 0:55
add a comment |
What is the use of -
func perform(_ aSelector: Selector!) -> unmanaged<AnyObject>!
in iOS?
- To call a method of a class?
- To add a selector method?
- To add a class delegate?
- To define a class? (I doubt it's this)
I was originally thinking that it it was to add a selector method, but after looking at it some more I think it may be "to call a method of a class." Selectors are used for target/action paradigms where I kick something off and when the event fires or finishes then it wants to fire off some kind of action method.
In this example do I pass it a parameter of a selector function then at the end of this "perform" function, I am returning an unmanaged object of any type? Does that even make sense?
Thanks!
ios swift
What is the use of -
func perform(_ aSelector: Selector!) -> unmanaged<AnyObject>!
in iOS?
- To call a method of a class?
- To add a selector method?
- To add a class delegate?
- To define a class? (I doubt it's this)
I was originally thinking that it it was to add a selector method, but after looking at it some more I think it may be "to call a method of a class." Selectors are used for target/action paradigms where I kick something off and when the event fires or finishes then it wants to fire off some kind of action method.
In this example do I pass it a parameter of a selector function then at the end of this "perform" function, I am returning an unmanaged object of any type? Does that even make sense?
Thanks!
ios swift
ios swift
asked Nov 14 '18 at 23:35
TSupermanTSuperman
485
485
Are you referring to the method fromNSObjectProtocol
which is from the Objective-C runtime?
– rmaddy
Nov 14 '18 at 23:41
@rmaddy --> I don't know. This was asked on a quiz that I was taking and I didn't have any other information for this question.
– TSuperman
Nov 14 '18 at 23:49
@rmaddy -> If the method was referring to the NSObjectProtocol, would it have a different meaning or do something that I wouldn't normally expect?
– TSuperman
Nov 15 '18 at 0:01
1
Basically it's something you would very rarely, if ever, use in Swift. It should rarely be used directly any more in Objective-C.
– rmaddy
Nov 15 '18 at 0:03
1
Indeed this used to be forbidden in Swift, and even now should be avoided, as Swift provides better ways. See stackoverflow.com/questions/24158427/… for example
– matt
Nov 15 '18 at 0:55
add a comment |
Are you referring to the method fromNSObjectProtocol
which is from the Objective-C runtime?
– rmaddy
Nov 14 '18 at 23:41
@rmaddy --> I don't know. This was asked on a quiz that I was taking and I didn't have any other information for this question.
– TSuperman
Nov 14 '18 at 23:49
@rmaddy -> If the method was referring to the NSObjectProtocol, would it have a different meaning or do something that I wouldn't normally expect?
– TSuperman
Nov 15 '18 at 0:01
1
Basically it's something you would very rarely, if ever, use in Swift. It should rarely be used directly any more in Objective-C.
– rmaddy
Nov 15 '18 at 0:03
1
Indeed this used to be forbidden in Swift, and even now should be avoided, as Swift provides better ways. See stackoverflow.com/questions/24158427/… for example
– matt
Nov 15 '18 at 0:55
Are you referring to the method from
NSObjectProtocol
which is from the Objective-C runtime?– rmaddy
Nov 14 '18 at 23:41
Are you referring to the method from
NSObjectProtocol
which is from the Objective-C runtime?– rmaddy
Nov 14 '18 at 23:41
@rmaddy --> I don't know. This was asked on a quiz that I was taking and I didn't have any other information for this question.
– TSuperman
Nov 14 '18 at 23:49
@rmaddy --> I don't know. This was asked on a quiz that I was taking and I didn't have any other information for this question.
– TSuperman
Nov 14 '18 at 23:49
@rmaddy -> If the method was referring to the NSObjectProtocol, would it have a different meaning or do something that I wouldn't normally expect?
– TSuperman
Nov 15 '18 at 0:01
@rmaddy -> If the method was referring to the NSObjectProtocol, would it have a different meaning or do something that I wouldn't normally expect?
– TSuperman
Nov 15 '18 at 0:01
1
1
Basically it's something you would very rarely, if ever, use in Swift. It should rarely be used directly any more in Objective-C.
– rmaddy
Nov 15 '18 at 0:03
Basically it's something you would very rarely, if ever, use in Swift. It should rarely be used directly any more in Objective-C.
– rmaddy
Nov 15 '18 at 0:03
1
1
Indeed this used to be forbidden in Swift, and even now should be avoided, as Swift provides better ways. See stackoverflow.com/questions/24158427/… for example
– matt
Nov 15 '18 at 0:55
Indeed this used to be forbidden in Swift, and even now should be avoided, as Swift provides better ways. See stackoverflow.com/questions/24158427/… for example
– matt
Nov 15 '18 at 0:55
add a comment |
1 Answer
1
active
oldest
votes
In Swift this is basically useless. It's bridged from Objective-C, where it used to be very useful (before ARC), but now it's a bit tricky.
The point of it is to send a message by name and get a result. Generally speaking that translates to calling a method of that name.
So basically this is "calling a method" and returning some data type? Not a nice way of doing it, but a long, obnoxious way of doing it?
– TSuperman
Nov 14 '18 at 23:44
1
It's only obnoxious in Swift. In ObjC, it's pretty elegant, and is the core tool used for all the target/action features like UIButton, NSTimer, and the like.
– Rob Napier
Nov 15 '18 at 0:02
Thanks! I have been writing more Swift code than Objective-C.
– TSuperman
Nov 15 '18 at 0:42
Is this method just short-hand for the ObjC runtime APIs likeclass_getMethodImplementation(AnyClass?, Selector)
?
– Alexander
Nov 15 '18 at 1:37
1
@Alexander It's a wrapper aroundobjc_msgSend
. You can see the source code for it here: opensource.apple.com/source/objc4/objc4-723/runtime/…
– Rob Napier
Nov 15 '18 at 13:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310364%2fswift-a-function-with-a-selector-argument-returns-an-unmanagedanyobject%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In Swift this is basically useless. It's bridged from Objective-C, where it used to be very useful (before ARC), but now it's a bit tricky.
The point of it is to send a message by name and get a result. Generally speaking that translates to calling a method of that name.
So basically this is "calling a method" and returning some data type? Not a nice way of doing it, but a long, obnoxious way of doing it?
– TSuperman
Nov 14 '18 at 23:44
1
It's only obnoxious in Swift. In ObjC, it's pretty elegant, and is the core tool used for all the target/action features like UIButton, NSTimer, and the like.
– Rob Napier
Nov 15 '18 at 0:02
Thanks! I have been writing more Swift code than Objective-C.
– TSuperman
Nov 15 '18 at 0:42
Is this method just short-hand for the ObjC runtime APIs likeclass_getMethodImplementation(AnyClass?, Selector)
?
– Alexander
Nov 15 '18 at 1:37
1
@Alexander It's a wrapper aroundobjc_msgSend
. You can see the source code for it here: opensource.apple.com/source/objc4/objc4-723/runtime/…
– Rob Napier
Nov 15 '18 at 13:46
add a comment |
In Swift this is basically useless. It's bridged from Objective-C, where it used to be very useful (before ARC), but now it's a bit tricky.
The point of it is to send a message by name and get a result. Generally speaking that translates to calling a method of that name.
So basically this is "calling a method" and returning some data type? Not a nice way of doing it, but a long, obnoxious way of doing it?
– TSuperman
Nov 14 '18 at 23:44
1
It's only obnoxious in Swift. In ObjC, it's pretty elegant, and is the core tool used for all the target/action features like UIButton, NSTimer, and the like.
– Rob Napier
Nov 15 '18 at 0:02
Thanks! I have been writing more Swift code than Objective-C.
– TSuperman
Nov 15 '18 at 0:42
Is this method just short-hand for the ObjC runtime APIs likeclass_getMethodImplementation(AnyClass?, Selector)
?
– Alexander
Nov 15 '18 at 1:37
1
@Alexander It's a wrapper aroundobjc_msgSend
. You can see the source code for it here: opensource.apple.com/source/objc4/objc4-723/runtime/…
– Rob Napier
Nov 15 '18 at 13:46
add a comment |
In Swift this is basically useless. It's bridged from Objective-C, where it used to be very useful (before ARC), but now it's a bit tricky.
The point of it is to send a message by name and get a result. Generally speaking that translates to calling a method of that name.
In Swift this is basically useless. It's bridged from Objective-C, where it used to be very useful (before ARC), but now it's a bit tricky.
The point of it is to send a message by name and get a result. Generally speaking that translates to calling a method of that name.
answered Nov 14 '18 at 23:41
Rob NapierRob Napier
203k28299425
203k28299425
So basically this is "calling a method" and returning some data type? Not a nice way of doing it, but a long, obnoxious way of doing it?
– TSuperman
Nov 14 '18 at 23:44
1
It's only obnoxious in Swift. In ObjC, it's pretty elegant, and is the core tool used for all the target/action features like UIButton, NSTimer, and the like.
– Rob Napier
Nov 15 '18 at 0:02
Thanks! I have been writing more Swift code than Objective-C.
– TSuperman
Nov 15 '18 at 0:42
Is this method just short-hand for the ObjC runtime APIs likeclass_getMethodImplementation(AnyClass?, Selector)
?
– Alexander
Nov 15 '18 at 1:37
1
@Alexander It's a wrapper aroundobjc_msgSend
. You can see the source code for it here: opensource.apple.com/source/objc4/objc4-723/runtime/…
– Rob Napier
Nov 15 '18 at 13:46
add a comment |
So basically this is "calling a method" and returning some data type? Not a nice way of doing it, but a long, obnoxious way of doing it?
– TSuperman
Nov 14 '18 at 23:44
1
It's only obnoxious in Swift. In ObjC, it's pretty elegant, and is the core tool used for all the target/action features like UIButton, NSTimer, and the like.
– Rob Napier
Nov 15 '18 at 0:02
Thanks! I have been writing more Swift code than Objective-C.
– TSuperman
Nov 15 '18 at 0:42
Is this method just short-hand for the ObjC runtime APIs likeclass_getMethodImplementation(AnyClass?, Selector)
?
– Alexander
Nov 15 '18 at 1:37
1
@Alexander It's a wrapper aroundobjc_msgSend
. You can see the source code for it here: opensource.apple.com/source/objc4/objc4-723/runtime/…
– Rob Napier
Nov 15 '18 at 13:46
So basically this is "calling a method" and returning some data type? Not a nice way of doing it, but a long, obnoxious way of doing it?
– TSuperman
Nov 14 '18 at 23:44
So basically this is "calling a method" and returning some data type? Not a nice way of doing it, but a long, obnoxious way of doing it?
– TSuperman
Nov 14 '18 at 23:44
1
1
It's only obnoxious in Swift. In ObjC, it's pretty elegant, and is the core tool used for all the target/action features like UIButton, NSTimer, and the like.
– Rob Napier
Nov 15 '18 at 0:02
It's only obnoxious in Swift. In ObjC, it's pretty elegant, and is the core tool used for all the target/action features like UIButton, NSTimer, and the like.
– Rob Napier
Nov 15 '18 at 0:02
Thanks! I have been writing more Swift code than Objective-C.
– TSuperman
Nov 15 '18 at 0:42
Thanks! I have been writing more Swift code than Objective-C.
– TSuperman
Nov 15 '18 at 0:42
Is this method just short-hand for the ObjC runtime APIs like
class_getMethodImplementation(AnyClass?, Selector)
?– Alexander
Nov 15 '18 at 1:37
Is this method just short-hand for the ObjC runtime APIs like
class_getMethodImplementation(AnyClass?, Selector)
?– Alexander
Nov 15 '18 at 1:37
1
1
@Alexander It's a wrapper around
objc_msgSend
. You can see the source code for it here: opensource.apple.com/source/objc4/objc4-723/runtime/…– Rob Napier
Nov 15 '18 at 13:46
@Alexander It's a wrapper around
objc_msgSend
. You can see the source code for it here: opensource.apple.com/source/objc4/objc4-723/runtime/…– Rob Napier
Nov 15 '18 at 13:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310364%2fswift-a-function-with-a-selector-argument-returns-an-unmanagedanyobject%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you referring to the method from
NSObjectProtocol
which is from the Objective-C runtime?– rmaddy
Nov 14 '18 at 23:41
@rmaddy --> I don't know. This was asked on a quiz that I was taking and I didn't have any other information for this question.
– TSuperman
Nov 14 '18 at 23:49
@rmaddy -> If the method was referring to the NSObjectProtocol, would it have a different meaning or do something that I wouldn't normally expect?
– TSuperman
Nov 15 '18 at 0:01
1
Basically it's something you would very rarely, if ever, use in Swift. It should rarely be used directly any more in Objective-C.
– rmaddy
Nov 15 '18 at 0:03
1
Indeed this used to be forbidden in Swift, and even now should be avoided, as Swift provides better ways. See stackoverflow.com/questions/24158427/… for example
– matt
Nov 15 '18 at 0:55