tristanhimmelman / ObjectMapper

Simple JSON Object mapping written in Swift
MIT License
9.15k stars 1.03k forks source link

Getting issues for binary infix operator '<-' for swift4.1, Xcode 9.3 #961

Open croyneaus4u opened 6 years ago

croyneaus4u commented 6 years ago
Invalid redeclaration of '<-' which differs only by the kind of optional passed as an inout argument ('[T]!' vs. '[T]?')

Invalid redeclaration of '<-' which differs only by the kind of optional passed as an inout argument ('T!' vs. 'T?')

Getting the above and similar warnings when trying to build for Swift4.1. It seems this type of overloading has been deprecated 4.1 onwards. Getting the below message for deprecation:

Overloading by kind of optional is deprecated and will be removed in a future release

I am using X-Code 9.3

croyneaus4u commented 6 years ago
screen shot 2018-04-21 at 9 02 39 pm
zeusent commented 6 years ago

Have you guys managed to fix these warnings? I have a similar problem

phoney commented 6 years ago

I believe that the implicitly unwrapped optional methods that are getting the warnings can be simply removed. They seem to all be identical to the plain unwrapped optional methods and as long as the compiler is going to use the plain unwrapped optional methods even for implicitly unwrapped parameters everything should 'just work' without the implicitly unwrapped optional methods.

chrisblessing commented 6 years ago

Hey all, came here to post this after I resolved all the warnings.

For me, removing all of the explicit unwrapping conflicts (e.g. param is T! version, not the optional T?) was the solution. This ObjectMapper project should be updated accordingly for Swift 4.1 as we can no longer build against 4.0 in Xcode 9.3. Leaving the methods with the optional params seemed the safest way to go, and sure enough the entire project runs just fine.

edit: really just reiterating what phoney said above.

You'll also need to update from flatMap -> compactMap.

You won't see these warnings against the Swift 4.0 toolchain fwiw, but that's not app-store compat.

zeusent commented 6 years ago

Hm... I've tried this but for some reason the compiler chooses the T overload instead of T? for my T! arguments :( This breaks things for me :(

zeusent commented 6 years ago

To be more explicit if I have these methods:

func <-(param: T) -> T { }
func <-(param: T?) -> T? { }
func <-(param: T!) -> T! { }

Removing func <-(param: T!) -> T! { } seems to have the compiler use func <-(param: T) -> T { } for T! parameters instead of func <-(param: T?) -> T? { } :(

phoney commented 6 years ago

@zeusent Couple questions: Are you using the latest Xcode compiler? When you say you have a similar problem are you referring to your use of ObjectMapper or something else?

zeusent commented 6 years ago

Yes, I have the latest Xcode version. And I’ve been looking all over the swift docs to find an explanation of this new warning that’s being triggered in Swift 4.1 and a recommended way of fixing it but couldn’t find any. My problem was not related to this project but some code of mine and this was the only place where I could find a similar problem. I’m sorry for “hijacking” the thread I guess just thought that sharing some info might help us all :-/

phoney commented 6 years ago

There's some discussion of this issue https://bugs.swift.org/browse/SR-6690 and https://bugs.swift.org/browse/SR-637 I think your case may be related to the return type of the functions (but I'm not sure).

firattemel commented 6 years ago

Looks like this issue is resolved in Xcode 9.3.1

trmquang commented 6 years ago

This is issue is not resolved in Xcode 9.3.1

croyneaus4u commented 6 years ago

When I tried to remove the T! & [T]! overloads. I get error saying:

Binary operator '<<-' cannot be applied to operands of type 'TopTitleHeader!' and '[String : Any]?' where class TopTitleHeader: Codable

Not working even in X-Code 9.3.1

Adrift001 commented 6 years ago

cocoapods version is 3.2, can update fast?

anudaweerasinghe commented 6 years ago

Updating to the latest version of ObjectMapper(3.2) and purging the Xcode derived data through the following command fixes the problem.

rm -rf ~/Library/Developer/Xcode/DerivedData/*

phoney commented 6 years ago

Doesn't seem fixed to me. I'm using Xcode 9.4.1 and pod version 3.3 and I see the warnings. Looking at the code I see checks for swift >= 4.1.5 and the swift version in this Xcode is 4.1.2.

I guess what was done was to prevent the compiler errors on swift 4.2 but leave the warnings in 4.1.

I would have preferred removing the warnings in swift 4.1. While this is a potentially breaking change users could choose to stay on an older version of the pod until they fix their code, which they'll have to do for swift 4.2 anyway.

When I change all those checks to swift >= 4.1 my code compiles without warnings and runs normally.

gcharita commented 6 years ago

@phoney The new release did not fix those warnings because IUO does not have the same behavior in Swift 4.1 compiler. This causes compilation errors in test targets of the library. #980

ParthMangi commented 6 years ago

For me this issue is still not resolved. I am using Xcode 9.4.1 and Swift 4.1 for my project. After applying for solution given from @chrisblessing it doesn't seem to work. Also as @phoney said there are some checks for >=4.1 In my project its not there.

My Xocde is 9.4.1

Project Swift Version 4.1

Pod ObjectMapper Target Version -> 3.3

ObjectMapper Version -> 5.0

Still warnings are coming up.

It would be great if fellow developers can help me I have been stuck at this issue for weeks.