To find the slope of a line between two points, we can use the formula:
m = (y2 - y1) / (x2 - x1)
where m is the slope, (x1, y1) and (x2, y2) are the two points.
In Swift, we can use the CGPoint struct to represent a point. Here's an example function that takes two CGPoints and returns the slope:
main.swift267 chars13 lines
We calculate the difference in x and y coordinates between the two points, and return the deltaY / deltaX ratio as the slope. If deltaX is zero (i.e. the line is vertical), we return infinity as the slope.
gistlibby LogSnag