You can just write self.optimalHeight = ourLayout.optimalHeight (Assuming flowLayout uses self rather than this, which I'm not sure about).