简体   繁体   English

如何在swift中比较CGPoints?

[英]How to compare CGPoints In swift?

I have 2 CGPoint like : 我有2个CGPoint喜欢:

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,我发现这个问题已经被问到但这是在Objective-C上所以任何研究都可以告诉我,我怎么能这样做是快速的?

CGPoint already implements the Equatable protocol, so you can compare using the == operator: CGPoint已经实现了Equatable协议,因此您可以使用==运算符进行比较:

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"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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