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 trial

iOS Build a Vending Machine App in Swift 2.0 Modeling An Interface Laying the Groundwork

sectionInset

sectionInset creates a margin or spaceing

 var sectionInset: UIEdgeInsets 

that is what api says on // https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UICollectionViewFlowLayout_class/

what i think is funny is in the example code it is

 layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)

so how come is layout "." as an attribute? and = sign and () paremters., is because there are multiple values? is that why the example code is different than API?

1 Answer

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

layout has a property on it called "sectionInSet".

layout.sectionInset

The "sectionInSet" property is of type "UIEdgeSets"

So in order to use this property "sectionInSet" you have to set it to a type of "UIEdgeSets". This was done when they initialized it as a UIEdgeSets type passing in the parameters named: top, left, bottom, right.

UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)

When you referenced the apple docs above, the declaration for "sectionInSet" displayed:

 var sectionInset: UIEdgeInsets 

If you click on the UIEdgeInsets portion it will take you to the developer page that explains how to create a UIEdgeInSet object. Located here: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIKitDataTypesReference/index.html#//apple_ref/swift/struct/c:@S@UIEdgeInsets