1

In C I can insert pairs of brackets to indicate a subscope.

int main() {
    int x = 5;
    {
        int y = 6;
        x += y; //Works
    }
    x = y+8; //Uh oh
}

In Swift, if I try something similar it will assume I'm trying to call the previous statement as a function, or errors for other reasons. How do I simply make a subscope in Swift, to deallocate variables earlier?

Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87

1 Answers1

1

You can try

do {   
     // insert sub scope code
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87