Git Product home page Git Product logo

iswift's Introduction

Objective-C to Swift Converter


iswift's People

Contributors

drkameleon avatar

Stargazers

yuchao lu avatar  avatar 煎饼果子 avatar Kersten Behrens avatar Mikal avatar jackey avatar Shingo Takagi avatar 端木 avatar  avatar Jeremy Bae avatar Kashee Ram Kushwaha avatar Swift Mage avatar Eremity avatar David DelMonte avatar Ullas Kumar avatar Dimo Hamdy avatar k avatar David C avatar Jochen Holzer avatar percy avatar Kevin Ross avatar Stephan Michels avatar  avatar Kaden Wilkinson avatar lich avatar Hiroki Nagasawa avatar XC avatar Peppermint - Code Editor for Mac avatar Rob avatar  avatar

Watchers

David DelMonte avatar  avatar Peppermint - Code Editor for Mac avatar Charles S Floading avatar Scott Hampson avatar

iswift's Issues

Does not recognize empty categories

For example:

@interface JournalTabViewController () //error on this line, unexpected (
@property (nonatomic) UIViewController *hi;
@end

@implementation JournalTabViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

@end

Parenthesis not respected

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)

Memory Leak?

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.

CGRectMake: Omit 0.0f attribute or change & Content Inset syntax

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))

in "[array addObject:@(app.processIdentifier)]" "@(" not handled

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.

Enums not converted

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

Swifty Loops

In Swift for-loops are written like this:

for i in 0..<10 {
    print("i: \(i)")
}

Source

Unable to convert file with NSString

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')

Error with code blocks

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 : ^

Class extensions not recognized

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.

Global Objects Referencing preventing further conversion.

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.

Need to follow #import for identifiers

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.

Unrecognized identifier

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 ?

"@implementation Foo {" not recognized

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

Several NS- struct types not being recognized

Examples:

NSHashEnumerator,NSHashTableCallBacks,NSMapEnumerator,NSMapTableKeyCallBacks,NSMapTableValueCallBacks,NSPoint,NSPointArray,NSPointPointer,NSRect,NSRectArray,NSSizeArray,NSSizePointer

Push Views: to new storyboard view.

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.

@Synthesize Value Errors and prevents conversion.

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.

x.y expressions - wrong output

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

    }

}

self. [Attribute]

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;

    }

}

User-defined types not being recognized

Using any user-defined type, either using the @interface declaration or the #imported header should automatically be registered as a type.

And thus avoid the resulting unrecognized #identifier errors.

#define preprocessor statements not being recognized

define statements - since they're rather challenging to be converted should be copied (and commented out) to the output.

Example:

#define SOME_MACRO(X) DO_SOMETHING_WITH(X)

Output:

// #define SOME_MACRO(X) DO_SOMETHING_WITH(X)

Floating-point constants not being recognized

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)'"

Convert documentation

Example:

/**
 *  yyyyyyyyyyy.
 *
 *  @param color zzzzzzzzzz
 *
 *  @return xxxxxxx
 */

Output:

/**
 *  yyyyyyyyyyy.
 *
 *  - param: color zzzzzzzzzz
 *
 *  - return: xxxxxxx
 */

Auto-convert an xcode project

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.

IBOutlet reference not being properly converted

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.