iswiftapp / iswift

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

Include class being implemented in the class list #133

Closed charlieMonroe closed 8 years ago

charlieMonroe commented 8 years ago

Example:

@implementation MNCountry

+(instancetype)countryWithCode:(NSString *)code{
    NSLocale *locale = [NSLocale currentLocale];
    NSString *name = [locale displayNameForKey:NSLocaleCountryCode value:code];
    if (name == nil){
        return nil;
    }

    MNCountry *country = [[self alloc] init];
    country->_countryCode = code;
    country->_countryName = [locale displayNameForKey:NSLocaleCountryCode value:code];
    return country;
}

@end

iSwift fails on this line:

MNCountry *country = [[self alloc] init];

Saying that MNCountry is an unknown type. Since this is within @implementation MNCountry, it should be a known type. A fix is, of course, to declare @class MNCountry; at the top, but that seems a bit unnecessary, IMHO.

drkameleon commented 8 years ago

Hmm... Interesting catch - how is it possible that I have missed that?!

drkameleon commented 8 years ago

Fixed as of the upcoming 2.1.

P.S. Not now (perhaps from 2.2 on), this will be part of a togglable "Smart Type Recognition" option. It's already a problematic thing (as we both know), so I'm already thinking of a few solutions...


Example:

@implementation aClass

- (void)someFunc {
    aClass* b;
}
@end
class aClass {

    func someFunc() {
        var b: aClass
    }

}