iswiftapp / iswift

Objective-C to Swift Converter
30 stars 3 forks source link

Option to automatically migrate [NS|CG][Point|Rect|Size] and their functions #174

Open charlieMonroe opened 8 years ago

charlieMonroe commented 8 years ago

Since in C and hence ObjC, structs cannot have any properties, or methods, there are various functions surrounding the basic graphics structures - for example, NSHeight(rect) will return the rect's height - which should be theoretically preferred to rect.size.height.

In Swift, most these methods do still exist, but the structures now have properties for accessing those values: rect.height in Swift will indeed return the height.

Aside from this, all these structures are declared as equatbale, so NSEqualRects can be rewritten using ==.

The same goes with the CG family of structs - CGRectGetMinX(rect) can be rewritten in Swift to rect.minX. For the entire list of functions, see the header file with NSRect or CGRect definition.

It would be really cool, if iSwift could automatically convert those.

Also, I would be personally really glad if all NS structures would be converted to CG structures - Apple has been slowly moving towards migrating Cocoa to CG structures anyway - since OS X 10.9 (I think), NSRect is just a typedef of CGRect - using these CG structures allows for a more reusable code, since there is no NSRect on iOS. During the migration to Swift, I'd like to clean up the code and this would be a significant improvement, IMHO. But I understand, if you say no.