Here's a sample code to find the area of a triangle in Swift:
main.swift305 chars11 linesIn the code above, we define a function called areaOfTriangle that takes two parameters, base and height, both of type Double. The function then calculates the area of the triangle using the formula 0.5 * base * height and returns the result.
To use the function, we pass in the values for the base and height of the triangle and store the result in a variable called area. We then print out the result using a formatted string that displays the values of the base, height, and area.
gistlibby LogSnag