Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

ROB TILLEY
ROB TILLEY
842 Points

Swift Brackets Syntax. Is there a basic rule for when to use {},[],().

Sorry if this seems silly but as a newbie to programming, I have difficulty remembering when to use the various bracket options when coding. Is there a general rule that can be applied so it makes it easy to remember?

2 Answers

Brendan Drake
Brendan Drake
4,162 Points

There is sort of rules, but at the same time, almost every programming language is different. In swift things that are being used by functions (such as if, else, while, or a custom function) require you put your steps to that function inside of {}. Things like parameters of functions, or things like the print function use (). The [] are mostly used for Arrays and lists. This is a very general list, and there are always exceptions, but I hope this helps, and good luck!

ROB TILLEY
ROB TILLEY
842 Points

Thanks Brendan. Appreciate the help. Rob