Swift: A function with a Selector argument returns an unmanaged?












5















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!










share|improve this question























  • 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
















5















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!










share|improve this question























  • 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














5












5








5


0






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!










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 23:35









TSupermanTSuperman

485




485













  • 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



















  • 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

















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












1 Answer
1






active

oldest

votes


















3














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.






share|improve this answer
























  • 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 like class_getMethodImplementation(AnyClass?, Selector)?

    – Alexander
    Nov 15 '18 at 1:37






  • 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











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
});


}
});














draft saved

draft discarded


















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









3














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.






share|improve this answer
























  • 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 like class_getMethodImplementation(AnyClass?, Selector)?

    – Alexander
    Nov 15 '18 at 1:37






  • 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
















3














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.






share|improve this answer
























  • 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 like class_getMethodImplementation(AnyClass?, Selector)?

    – Alexander
    Nov 15 '18 at 1:37






  • 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














3












3








3







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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 like class_getMethodImplementation(AnyClass?, Selector)?

    – Alexander
    Nov 15 '18 at 1:37






  • 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



















  • 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 like class_getMethodImplementation(AnyClass?, Selector)?

    – Alexander
    Nov 15 '18 at 1:37






  • 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

















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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma