Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot seem to use CGRectIntegral and CGRectInset functions in Swift

Tags:

ios

swift

Sorry for the novice question.

But just as the title says, I can't seem to use these functions in Swift 3. I have tried by importing the CoreGraphics library, but to no avail.

Does anyone know why?

Thanks in advance.

like image 259
user3608914 Avatar asked Nov 29 '16 11:11

user3608914


3 Answers

The functions are working fine, but their names have changed (a bit):

  let frame = CGRect.zero
  let x = frame.integral
  frame.insetBy(dx: 0, dy: 0)
like image 164
Samip Shah Avatar answered Oct 13 '22 01:10

Samip Shah


  1. import CoreGraphics

  2. let rect = CGRect() let rectIntegral = rect.integral

Thanks:)

like image 20
Karthick Selvaraj Avatar answered Oct 13 '22 00:10

Karthick Selvaraj


Actually you don't need to import CoreGraphics.

In Swift 3 Objective-C function

CGRect CGRectIntegral(CGRect rect)

has become

var integral: CGRect { get }

and

CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy);

has become

func insetBy(dx: CGFloat, dy: CGFloat) -> CGRect

Both API have to be called on the CGRect instance for example

let newFrame = view.frame.insetBy(dx: 10.0, dy:10.0)

A hint to find out yourself

  • Press ⇧⌘0
  • Type CGRectIn in the search field
  • In the popup menu set the language to Objective C
  • Select one of the functions
  • Set the language to Swift
like image 35
vadian Avatar answered Oct 13 '22 00:10

vadian