- For Issues/Feedback/Request, check here
- For the Wiki (still under construction), check here
iswiftapp / iswift Goto Github PK
View Code? Open in Web Editor NEWObjective-C to Swift Converter
Objective-C to Swift Converter
Example:
@implementation SomeClass
#pragma mark SomeComment
...
@end
Expected output:
class SomeClass
// MARK: SomeComment
...
@end
Result: Error
For example:
@interface JournalTabViewController () //error on this line, unexpected (
@property (nonatomic) UIViewController *hi;
@end
@implementation JournalTabViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
@end
CGFloat u = (pointX - lineStartPointX) * (lineEndPointX - lineStartPointX);
becomes:
let u: CGFloat = pointX-lineStartPointX*lineEndPointX-lineStartPointX
Perhaps you could simply strip the trailing semicolon and leave the rest intact? (although I assume it's FAR more complicated than that and involves parse trees etcetera)
Example:
NSLog(@"This is a string: %@",str);
Should be:
print("This is a string: \(str)");
To be implemented.
When pasting or opening a .m file that is more than a 1000 lines of code iSwift slows down.
Steps to reproduce:
1.) Open up iSwift
2.) Copy and paste a large .m file with various functions OR open up .m file
Expected results:
The application should parse through the .m file and lines of code and produce the Swift conversion.
Actual results:
The application is still responsive however its so slow that the conversion often never eventuates. Occasionally cause iSwift to crash.
System:
MacBook Pro 16GB Memory, 2.6 GHZ,
Open Applications:
Safari, XCode, iSwift, Mail.
I may have already raised this one. I can't remember sorry. When converting a CGRectMake it doesn't like the 0.0f attribute and fails. Also Content Inset Syntax I believe requires a "!" when referencing .contentInset. This particular is true when referencing a UITableView. I put these two issues together as it was in the same code block.
Try code:
(Objective C)
self.automaticallyAdjustsScrollViewInsets = NO;
AirportPlatesTableView.contentInset = UIEdgeInsetsZero;
AirportPlatesTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.AirportPlatesTableView.bounds.size.width, 0.01f)];
Expected Results:
(Swift)
self.automaticallyAdjustsScrollViewInsets = false
AirportPlatesTableView!.contentInset = UIEdgeInsetsZero
AirportPlatesTableView!.tableHeaderView = UIView(frame:CGRectMake(0.0,0.0,self.AirportPlatesTableView!.bounds.size.width,0.01f))
(double check Swift syntax as I'm not 100%)
Actual Results:
(Swift)
self.automaticallyAdjustsScrollViewInsets = false
AirportPlatesTableView.contentInset = UIEdgeInsetsZero
AirportPlatesTableView.tableHeaderView = UIView(frame:CGRectMake(0.0f,0.0f,self.AirportPlatesTableView.bounds.size.width,0.01f))
Class does. But the inherited one is ignored.
Example:
@interface someClass : NSObject
@end
@implementation someClass
@end
See here: #42 (comment)
Trying to convert https://github.com/gnachman/iTerm2/blob/master/sources/AppleScriptTest.m
- (NSArray *)processIdsForTestApp {
NSMutableArray *array = [NSMutableArray array];
for (NSRunningApplication *app in [[NSWorkspace sharedWorkspace] runningApplications]) {
if ([app.bundleIdentifier isEqualToString:kTestBundleId]) {
[array addObject:@(app.processIdentifier)];
}
}
return array;
}
fails with "Unexpected (" in " [array addObject:@(app.processIdentifier)];" line.
Example:
class someClass {
var someVar: Bool?
}
Becomes:
class someClass {
var someVar: Bool?
}
Using CGFloat
will throw a parse error.
For now, float
has to be used.
Example:
typedef NS_ENUM (NSUInteger, TestEnum) {
TestEnumCase1,
TestEnumCase2,
TestEnumCase3,
TestEnumCase4,
TestEnumCase5
};
Output:
enum TestEnum {
case Case1, Case2, Case3, Case4, Case5
}
If objectivec compatibility is required (which should also be a setting imo...It changes a lot of things), then @objc enum TestEnum: Int
Example:
self.someMethod()
Could be:
someMethod()
Example:
for (int i=0; i<10; i++)
{
}
Using #pragma
will throw a parse error.
Example:
#pragma mark something
i++
gets translated in i--
.
#import
statements fail when a known (class) type is included, e.g.
#import <UIKit/UIKit.h>
Example code:
//
// NSString+SomethingNew.h
//
#import <Foundation/Foundation.h>
@interface NSString (SomethingNew)
-(BOOL)newMethodExample;
@end
//
// NSString+SomethingNew.m
//
#import "NSString+SomethingNew.h"
@implementation NSString (SomethingNew)
#pragma mark - Public Getter Methods
- (BOOL)newMethodExample {
return true;
}
@end
Error:
Unexpected #type : ('NSString')
Example:
void (^someBlockName)(NSString *someParam) = ^(NSString *someParam) {
if (someParam) {
// 1
} else {
// 2
}
};
or
void (^someBlockName)(NSString *someParam);
someBlockName = ^(NSString *someParam) {
// code
};
Expected result: Code block converted to closure
Result: Error - Unexpected : ^
Currently Class extensions' definition is not being recognized, e.g.
@interface UIColor (MyExtension)
or
@implementation UIColor (MyExtension)
A quick fix is to simply change the syntax like "UIColor_MyExtension" - but it's in my to-fix list.
When referencing a global object as indicated with the code below from another .m file (NSObject or other) it fails on the = I believe.
Try with the following code:
GlobalObjects *setObjects = [GlobalObjects sharedGlobalObjects];
Expected Results:
Perhaps: var setObjects: GlobalObjects = GlobalObjects.sharedGlobalObjects()
Actual Results:
Error's out at specific line preventing it from continuing forward.
Trying to convert https://github.com/gnachman/iTerm2/blob/master/sources/AlertTrigger.m, fails on:
#import "PTYSession.h"
...
- (BOOL)performActionWithCapturedStrings:(NSString *const *)capturedStrings
capturedRanges:(const NSRange *)capturedRanges
captureCount:(NSInteger)captureCount
inSession:(PTYSession *)aSession
onString:(iTermStringLine *)stringLine
atAbsoluteLineNumber:(long long)lineNumber
stop:(BOOL *)stop {
if (disabled_) {
return YES;
}
with: "unexpected: #identifier ('PTYSession')".
Based on your comment in another issue, list of identifiers is hard-coded and obviously will never include PTYSession
, which is defined in "PTYSession.h". Without being able to resolve this generically by following #import statements, it's not going to be practical to convert real-life projects.
Drag'n'drop is to be totally disabled on the Swift view - no point at all in its being there.
@property
definitions within an @interface
are recognized.
Class variables are not.
UIStatusBarStyle
is the cause of the error. If I change it for NSString, it works.
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@implementation Test
+ (UIStatusBarStyle)statusBarStyleForColor:(UIColor *)backgroundColor {
return UIStatusBarStyleDefault;
}
@end
Similar to #27 but for UIKit enums ?
A snippet code like this:
@implementation AdvancedWorkingDirectoryWindowController {
// Advanced working dir sheet
IBOutlet NSMatrix* _windowDirectoryType;
IBOutlet NSTextField* _windowDirectory;
IBOutlet NSMatrix* _tabDirectoryType;
IBOutlet NSTextField* _tabDirectory;
IBOutlet NSMatrix* _paneDirectoryType;
IBOutlet NSTextField* _paneDirectory;
}
is not parsed. It complains about "unrecognized {"
Found by trying to convert https://github.com/gnachman/iTerm2/blob/master/sources/AdvancedWorkingDirectoryWindowController.m
Examples:
NSHashEnumerator
,NSHashTableCallBacks
,NSMapEnumerator
,NSMapTableKeyCallBacks
,NSMapTableValueCallBacks
,NSPoint
,NSPointArray
,NSPointPointer
,NSRect
,NSRectArray
,NSSizeArray
,NSSizePointer
As initially suggested here: #16 (comment)
#undef
statements should be copied (and commented out) to the output.
Example:
#undef SOMETHING
Output:
// #undef SOMETHING
When trying to push to a new starboard instance i.e. new view an error comes to the = symbol suggesting that it requires additional syntax. This error my be similar to the other error I raised in relation to Global Objects. However, that is an assumption.
Using the following Code:
PlatesViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"PlatesView"]
Expected Results:
var detail: PlatesViewController = self.storyboard.instantiateViewControllerWithIdentifier("PlatesView")
(double check the syntax on this one as I'm not 100%)
Actual Results:
Error preventing to further convert.
Add "Do not show again" checkbox to the "Are you sure?" prompt when attempting to close the app
There seems to be an issue when trying to convert @synthesize. Now I know the Swift does things slightly different as in some things are not needed. However, I am unsure if this is an issue or by design.
Try with the following code:
@synthesize copyrightLabel;
Expected Results:
Perhaps blank? Not sure.
var copyrightLabel?
Actual Results:
Error's out at @synthesize Line.
Example:
@implementation aClass
- (void)main {
NSRect r;
r.origin.x = 2;
}
@end
Should output:
class aClass {
func main() {
var r: NSRect
r.origin.x=2
}
}
I'm not even sure how to classify this however, I'll just provide the details and you can update the title to reflect accordingly as I honestly don't know.
When converting a TableView Function numberOfRowsInSection there seems to be an issue when assigning or configuring self attributes among array count function.
Please test with the following code.
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
self.tabBarController.delegate = self;
if (platesArray != nil || [platesArray count] != 0)
{
UIViewController *selectedVC = [self.tabBarController.viewControllers objectAtIndex:self.tabBarController.selectedIndex];
NSString *selectedItemTag = selectedVC.tabBarItem.title;
NSLog(@"%@",selectedItemTag);
if ([selectedItemTag isEqualToString:@"Approach"]){
return approachArray.count;
}
if([selectedItemTag isEqualToString:@"Airport"]){
return airportArray.count;
}
if([selectedItemTag isEqualToString:@"Arrivals"]){
return arrivalArray.count;
}
if([selectedItemTag isEqualToString:@"Departures"]){
return departureArray.count;
}
else{
return platesArray.count;
}
}
else
{
//Return nothing as something has gone wrong with the array.
return 0;
}
}
Expected results: (PLEASE NOTE THIS IS ONLY WHAT I THOUGHT IT SHOULD BE AND MAY NOT BE CORRECT)
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
self.tabBarController.delegate = self
if platesArray != nil || platesArray.count() != 0 {
var selectedVC: UIViewController = self.tabBarController.viewControllers.objectAtIndex(self.tabBarController.selectedIndex)
var selectedItemTag: String = selectedVC.tabBarItem.title
NSLog("%@", selectedItemTag)
if selectedItemTag.isEqualToString("Approach") {
return approachArray.count
}
if selectedItemTag.isEqualToString("Airport") {
return airportArray.count
}
if selectedItemTag.isEqualToString("Arrivals") {
return arrivalArray.count
}
if selectedItemTag.isEqualToString("Departures") {
return departureArray.count
}
else {
return platesArray.count
}
}
else {
return 0
}
}
Actual Results:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
.delegate=self
if platesArray!=nil||platesArray.count()!=0 {
var selectedVC: UIViewController = .viewControllers.objectAtIndex(.selectedIndex)
var selectedItemTag: String = .title
NSLog("%@",selectedItemTag)
if selectedItemTag.isEqualToString("Approach") {
return .count;
}
if selectedItemTag.isEqualToString("Airport") {
return .count;
}
if selectedItemTag.isEqualToString("Arrivals") {
return .count;
}
if selectedItemTag.isEqualToString("Departures") {
return .count;
} else {
return .count;
}
} else {
return 0;
}
}
Using any user-defined type, either using the @interface
declaration or the #import
ed header should automatically be registered as a type.
And thus avoid the resulting unrecognized #identifier
errors.
Example:
#define SOME_MACRO(X) DO_SOMETHING_WITH(X)
Output:
// #define SOME_MACRO(X) DO_SOMETHING_WITH(X)
I believe that the CGRectMake is having issues when the values are 0.0f. This needs to be confirmed as I'm not 100%.
Steps to reproduce.
1.) Copy the following code into iSwift
AirportPlatesTableView.contentInset = UIEdgeInsetsZero;
AirportPlatesTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.AirportPlatesTableView.bounds.size.width, 0.01f)];
2.) Review the error provided.
Expected results:
I believe they should be as followed, however I'm no expert in Swift.
AirportPlatesTableView.contentInset = UIEdgeInsetsZero
AirportPlatesTableView.tableHeaderView = UIView(frame: CGRectMake(0.0, 0.0, self.AirportPlatesTableView.bounds.size.width, 0.01))
Actual Results:
Errors stipulating that "Unexpected : #constant ('.0f)'"
Example:
/**
* yyyyyyyyyyy.
*
* @param color zzzzzzzzzz
*
* @return xxxxxxx
*/
Output:
/**
* yyyyyyyyyyy.
*
* - param: color zzzzzzzzzz
*
* - return: xxxxxxx
*/
I notice that when you drag into the window it just read it in as text.
Being able to drag and drop an objective-c project and get a swift copy version would be pretty neat. Or at least a directory of swift files.
Is it possible to have the @implementation & @interface as a greyed out place holder in the left side of the objective c panel? The purpose is just to illustrate the minimums of what is needed. Sounds way basic but nice to illustrate.
Example:
@implementation aClass
- (IBAction)someAction:(id)sender {
}
@end
Should become:
class aClass {
@IBAction func someAction(sender: AnyObject) {
}
}
Steps to reproduce:
1.) Open up iSwift
2.) The following set of code.
@Property (strong, nonatomic) IBOutlet UITableView *AirportPlatesTableView;
Expected results:
@IBOutlet var AirportPlatesTableView: UITableView?
Actual results:
var airportICAOCode: IBOutlet?
Again unsure if this is something we the programmer needs to adjust after the conversion or of its something that is an error. Your call.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.