Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialROB TILLEY
842 PointsSwift 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
4,162 PointsThere 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
842 PointsThanks Brendan. Appreciate the help. Rob