简体   繁体   中英

How to compare CGPoints In swift?

I have 2 CGPoint like :

let a : CGPoint = CGPointMake(1, 1)
let b : CGPoint = CGPointMake(1, 1)

if Both are same then I want to do something.

This is just an example but I want to compare this two CGPoint and I found this question which is already asked but this is on objective-C so can anybudy tell me how can I do this is swift?

CGPoint already implements the Equatable protocol, so you can compare using the == operator:

if a == b {
}

Small example for you:

let a : CGPoint = CGPointMake(1, 1)
let b : CGPoint = CGPointMake(1, 1)

if (a == b)
{
  var str = "YES"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM