Property wrappers are not yet supported on local properties error message

I am new to swift and coped-pasted some code but it does not compile and I don't understand why and can't figure out why.

// ObservableObject that limits text fields to numbers (digits) only            
class NumbersOnly: ObservableObject {                                           
    @Published var value = "" {                                                 
        didSet {                                                                
            let filtered = value.filter { $0.isNumber }                         
                                                                                
            if value != filtered {                                              
                value = filtered                                                
            }                                                                   
        }                                                                       
    }                                                                           
}                                                                               
                                                                                

The code is on github here: DeliveryBox/MobileApp/DeliveryBox_iOS/DeliveryBox_iOS/ContentView.swift at main · RobertPHeller/DeliveryBox · GitHub

I have an "old" MacBook (2013 vintage, running MacOS 10.15.8), with XCode 12.4 (Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28). (I know this is old, but it is what I have and I really can't afford to buy a new Mac, esp. since I am not really a mac user.)

Hello, @RobertPHeller

You should at least show the offending piece of code, by enclosing it between a pair of three backtick characters (```):

```
Paste Code Here
```

If you do that, the code will appear like this: :slight_smile:

@main
enum Driver {
    static func main() async throws {
        let f = f_or_g (true)
        print (f ())
        // Error: Missing argument for parameter #1 in call
    }
}

func f () -> Int {
    return 2
}

func g () -> Int {
    return 3
}

func g (_ u: Int) -> Int {
    return 5
}


#if true
    // Does not compile
    func f_or_g (_ u: Bool) -> (Int) -> Int {
        return u ? f : g
        // Error: Cannot convert value of type '@Sendable () -> Int' to specified type '(Int) -> Int'
    }
#elseif true
    // Compiles
    func f_or_g (_ u: Bool) -> () -> Int {
        if u {
            return f
        }
        else {
            return g
        }
    }
#else
    // Compiles
    func f_or_g (_ u: Bool) -> @Sendable () -> Int {
        return u ? f : g
    }
#endif

OK, I pasted it. (I don't really like forums -- the editers are strange and hard (for me) to use. I did include a link to the file on github.

OK, I moved the Observer code to a separate file and error went away. I also appears the there is something fishy with the IDE. Errors show up in the IDE's editor, but the errors go away when I explicitly Build the project.

What kind of errors show up?

The errors are supurious. I think the IDE is getting confused because I am
using an external editor and it generating errors on partially re-loaded
files. I am not ignoring any errors that automagically popup when the file
gets modified. I just explicitly select Build or Run from the Product menu.

If your IDE is flaky, another source of compiler truth for small programs from old computers is the "godbolt" compiler explorer, which supports Swift both modern and ancient:

https://godbolt.org

Building the project is your source of truth. If errors disappear after building, then it is not a real problem in code.

1 Like