Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using the Swift Programming language. Here is the code:

C#
class CalculatorBrain9iOS{

    ***bunch of code***

    private var accumulator = 0.0
    private var pending: PendingBinaryOperationInfo?

    private struct PendingBinaryOperationInfo {
        var binaryFunction: (Double, Double) -> Double
        var firstOperand: Double
    }

    func ...(...) {
        if let operation = ... {
            switch operation {
            case ...
            case RandomFunction.ThisCase(let function):
                pending = PendingBinaryOperationInfo(binaryFunction: function,
                firstOperand: accumulator)
                
            }
        }
    }
 
   ***bunch of code***

}


What I have tried:

I want to change the private struct (PendingBinaryOperationInfo) to a class. It doesn't need inheritance so I figured I could just replace "private struct" with "class". But I keep getting initializer error messages on that line. Is it strictly because that new class is a nested class? Or are there other factors involved?

I guess my other big question here is: Aside from inheritance and value/reference, what other differences exist between classes and structs that makes it so that I can't just replace a struct with a class and still have the program run perfectly fine?

*PS: Sorry, buts it's not letting me indent the lines for some reason.
Posted
Updated 30-Apr-16 3:37am
v4
Comments
Maciej Los 30-Apr-16 13:29pm    
Try to change private struct PendingBinaryOperationInfo to private static class PendingBinaryOperationInfo.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900