Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift function scope - referencing self (to mean "self as the enveloping function")

Tags:

ios

swift

iphone

Take this basic function:

func sampleFunction ()
{
    print( self )
}

Here self refers to the class instance that envelopes it, rather than - as might arguably make more sense - the function that envelopes it.

How does one get a reference to the enveloping function rather than its enveloping class instance?

Ideally, I'm looking to do something like this:

func sampleFunction ( value: Int )
{
    print( selfAsEnvelopingSampleFunction, value )
}
like image 333
Joseph Beuys' Mum Avatar asked Dec 04 '15 14:12

Joseph Beuys' Mum


1 Answers

If you want to print the name of the function, you can use __FUNCTION__

print(__FUNCTION__)

in your print statement, otherwise just use sampleFunction as an argument .

like image 68
Dániel Nagy Avatar answered Nov 03 '22 01:11

Dániel Nagy