0

I had a piece of code that was working on Swift 2.X version, but, after update the code and syntax to Swift 3.0 it is working on a strange way.

I have the following structure wrote on Objective-C:

Class A:

@interface A : NSObject
{
    // some properties
}

Class Expense:

@interface Expense : A {
    @property (strong, nonatomic) NSString* Description;
}

On Swift 2.X I had the following code:

if let expense = DataManager.sharedDataManager().expenseForExpenseId(id) {
    var description = expense.Description
}

When I updated to Swift 3.0 the code was changed to:

if let expense = DataManager.shared().expense(forExpenseId: id) {
   // expense is a variable from the Expense class
   var description = expense.description
}

The problem that I am facing is that when I use expense.description I'm getting the value for the description (lowerCamelCase) property from the NSObject class (parent of parent class) instead of the value for the Description (UpperCamelCase) property from the Expense Class. I had to change the expenseType.Description to expenseType.description because of the new syntax on Swift 3.0

I have a workaround to fix it, create a get method on the Expense Class and call it from Swift 3.0:

@interface Expense : A {
    @property (strong, nonatomic) NSString* Description;
    -(NSString*) getDescription(){
        return Description;
    }
}

Is this a known problem? Do you know a better solution for this problem?

DavidGSola
  • 697
  • 5
  • 17
  • 3
    I would just rename the property, `Description` is a bad choice, it does not follow any naming conventions and could conflict with `description` in other situations like Key-Value Coding. If that is not possible, define a different name for Swift with NS_SWIFT_NAME, see http://stackoverflow.com/questions/40157131/converting-to-swift-3-renamed-my-own-objective-c-method for an example. – Martin R Jan 18 '17 at 08:15
  • 1
    ya you should change the property name. Do not use `description` – Quang Hà Jan 18 '17 at 08:53

0 Answers0