When I built the application that used CoreData in swift3 with swift4, the following check dependencies came out
The use of Swift3 @objc reference in Swift4 mode is decremented. Please address decremented @objc reference warnings, test your code with "Use of decreasing Swift3 @objc reference" logging enabled, and then disable reference by changing the "swing" warning @setting" for "swinging"
I'd like to erase this warning. Can someone help me?
swift3 swift4 coredata
The warning is always displayed when you migrate a Swift3 project to Swift4 whether or not you are using CoreData.
On Xcode, there is an item named SWIFT_SWIFT3_OBJC_INFERENCE in the target Build Settings of your project, so please find it.It should be on.(It may look different depending on the Xcode version, setting, etc.)
Rewrite this setting to Off.(Default is the same, but Off is still easier to understand.) The half of the warning message means that the behavior with this setting turned on is deprecated on Swift4, so don't use it.Rewriting this setting should prevent warnings.
However, depending on the application, setting this setting to Off may crash at runtime.The other half of the warning messages tell you to debug enough before turning it off.
However, the specific method (what kind of log output should be turned on) is difficult to understand and I don't remember that it was very helpful in my own experience, so I recommend that you turn it off and debug it enough.
By the way, "Swift3@objc reference" has something to do with this change in the Swift language.
SE-0160 Limiting@objc reference
@objc
is an annotation that indicates that methods and properties (formerly classes) are Objective-C compatible, but sometimes methods and properties are automatically Objective-C compatible without @objc
under certain conditions."I don't know what the conditions are, I often get an Objective-C name (selector), I often don't get Objective-C at all when I automatically convert Swift-like names, and above all, there are disadvantages such as compilation binaries getting bigger," SE-01/p> says.
Therefore, if you turn off the above settings for methods and properties that may be invoked internally in iOS or through a selector from your code, the Unrecognized selector
can cause a runtime crash error.
If you are using #selector
correctly, the Swift migration tool will add @objc
, but if you are writing old or difficult to understand (for example, code based on KVC or KVO), the migration tool may not detect it well.
(CoreData is actually a framework that relies heavily on Objective-C's runtime processing, which is one of the few cases where @objc
can be implicitly supplemented.)
"It may have been a little hard to understand in the second half, but you should remember that ""With Swift4, if you don't add @objc
(express), the code that worked up to Swift3 may not work."""
© 2024 OneMinuteCode. All rights reserved.