Rafał Sroka
Rafał Sroka

Reputation: 40030

Swift 3 alternative for NSStringFromCGSize

In Objective-C we have NSStringFromCGSize method that converts CGSize to NSString. I want to make my code as Swifty as possible and I don't want to use this vintage method.

public func NSStringFromCGSize(_ size: CGSize) -> String

Is there a Swift 3 API for that? I know I could easily code a helper function but I might be reinventing the wheel, maybe there is already something like that built in into the framework.

Please help.

Upvotes: 1

Views: 572

Answers (2)

Zapko
Zapko

Reputation: 2461

In swift 4 we can use

let string = NSCoder.string(for: size)

Upvotes: 2

Joshua Vidamo
Joshua Vidamo

Reputation: 182

Why not just encase your CGSize in \() like

let string = "\(CGSize.zero)"

Upvotes: 1

Related Questions