how to use values returned by Swift function

前端 未结 5 409
不思量自难忘°
不思量自难忘° 2021-01-26 01:36

I am trying to use a Swift function to place a circle in the centre of a view so it is always on centre regardless of screen size. I can draw the circle at a point defined by a

5条回答
  •  深忆病人
    2021-01-26 02:11

    In your ViewDidLoad method, you are only calling the method, but not storing the returned values. All you need to do to fix this is to create a variable and assign it to the call of your function.

    Example:

    let center = screenCentre()
    print(center)
    

    Now, the variable center will contain the coordinates of your screen's center. And in subsequent code, you can use center like you would with any other variable.

提交回复
热议问题