Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending a struct which is inside another struct

I'm trying to extend a struct that is already inside a struct. When I write the following code, I get

declaration is only valid at file scope.

struct A {
    struct AA {

    }
}

extension A {
    extension AA {

    }
}

Is it invalid to write an extension inside an extension?

like image 475
haider_kazal Avatar asked Sep 24 '26 11:09

haider_kazal


1 Answers

It seems like the only way to do that is:

extension A.AA
{
   func test()
   {
      print("Test")
   }
}

It just worked in my playground

like image 104
Andrey Chernukha Avatar answered Sep 26 '26 01:09

Andrey Chernukha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!