Q:

Swift iOS -How to find CGPoint x/y values for CollectionView's second Section

I have a collectionView with 2 sections. The frame of the first section will depend on the number of cells inside of it. Since the total number of cells (firstSectionData.count) in the first section will vary I need to find the CGPoint for the Second Section. I specifically need to find out the x/y values of where the second section begins. 
The frame will also be suffice because I can extract them from there. How can I find this out?
var cv: UICollectionView!
let firstSectionCell = "FirstSectionCell"
let secondSectionCell = "SecondSectionCell"
let secondSectionHeaderView = "SecondSectionHeaderView"
let firstSectionData = [String]()
let secondSectionData = [String]()
let cellHeight: CGFloat = 50
let headerHeight: CGFloat = 60

override func viewDidLoad() {
    super.viewDidLoad()

    let layout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
    layout.scrollDirection = .horizontal

    cv = UICollectionView(frame: view.frame, collectionViewLayout: layout)
    cv.delegate = self ; cv.dataSource = self
    cv.register(FirstSectionCell.self, forCellWithReuseIdentifier: firstSectionCell)
    cv.register(SecondSectionCell.self, forCellWithReuseIdentifier: secondSectionCell)
    cv.register(SecondSectionHeaderView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: secondSectionHeaderView)
    view.addSubview(cv)
}

func numberOfSections(in collectionView: UICollectionView) -> Int {
    return 2
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    if section == 0{
        return firstSectionData.count // varies
    }
    return secondSectionData.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    if indexPath.section == 0{
        return firstSectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: self.firstSectionCell, for: indexPath) as! FirstSectionCell
    }

    return secondSectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: self.secondSectionCell, for: indexPath) as! SecondSectionCell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: view.frame.width, height: self.cellHeight) // height is 50
}

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    let headerView: UICollectionReusableView?
    if kind == UICollectionElementKindSectionHeader{
        let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: self.secondSectionHeaderView, for: indexPath) as! SecondSectionHeaderView
        headerView = header
    }
    return headerView!
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {

    if section == 0{
        return CGSize.zero // the first section doesn't have a header
    }

    return CGSize(width: view.frame.width, height: self.headerHeight) // header height is 60 for the second section
}

A:

This type of information is kept by the collection view's layout manager. The collection view provides two convenience methods:
layoutAttributesForItem(at:)

and:
layoutAttributesForSupplementaryElement(ofKind:at:)

These return a value of UICollectionViewLayoutAttributes?. This in turn has properties such as frame and others.
If you want the frame of a specific item in a collection view you would do:
let frame = collectionView.layoutAttributesForItem(at: someIndexPath)?.frame

If you want the frame of a section header in a collection view you would do:
let frame = collectionView.layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: someSectionIndexPath)

