Swift: how to maximize warnings in Xcode? What is the equivalent for -Wall in swiftc?
No. C accumulated layer-upon-layer of warnings and then barnacles like "warnings that aren't part of 'all warnings'" over many years and many compilers, coupled with a language that allows a lot of things you generally should never do.
Swift is young and has broken backward compatibility several times in its short life. It hasn't been around long enough to need bizarre backward-compatibilty options yet. Many of the things C adds as warnings, Swift just makes illegal or requires you make explicit.
That said, there absolutely are other layers of warnings that exist already. The first set are found via the static analyzer (Cmd-Shift-B in Xcode), and the second exist in tools like swiftlint which fills the same role as linters in C. The line between a linter and a compiler warning is vague and shifting, and you may see some things move from the linter to the compiler over time. But I still doubt you'll ever see a warning system as convoluted as GCC's (which Clang inherited).
How to suppress a specific warning in Swift
At present (Xcode 7.1), there seems to be no way of suppressing a specific warning in Swift (see e.g. How to silence a warning in swift).
In your special case, you can fool the compiler by
computing the number of bytes in a word:
func f() -> Int {
switch (__WORDSIZE / CHAR_BIT) { // Or: switch (sizeof(Int.self))
case 4: return 1
case 8: return 2
default: return 0
}
}
This compiles without warnings on both 32-bit and 64-bit architectures.
How to add warning to all uses of native swift function/method?
I don't think you can.
So, I believe you have only two options
First:
protocol Warnings {
#warning("Your warning message")
func hasSuffix(_ suffix: String) -> Bool
}
extension String: Warnings {}
But in this case warning will not be placed where you call a function. Instead, it will be placed where you used #warning
.
Second:
If you really don't want anyone to use some function
extension String {
func hasSuffix(_ suffix: String) -> Bool {
fatalError("Do not use this method")
}
}
Why is there no Swift equivalent for adding an action to a view?
The target/selector mechanism is how UIControl
(and similar classes) was written long ago, in Objective-C, before even Objective-C blocks were a thing.
Your question is just as valid for Objective-C. Why doesn't UIControl
(and similar) provide a block based API instead of the dated target/selector pattern?
So it's not a matter of updating Swift. It's a question of adding a block/closure based API to relevant classes that use the target/selector pattern.
If you do a little searching on GitHub you will find a closure based Swift API that actually does what you want. Of course, its implementation is to use the old target/selector APIs.
IOS Chart compiler warnings with Xcode 11.5
Go the Target's Build Settings
and set Inhibit All Warnings
to YES
.
OR
If you're using cocoapods you can automatically set it to YES
by adding these lines into your Podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['GCC_WARN_INHIBIT_ALL_WARNINGS'] = "YES"
end
end
end
OR
Just declare inhibit_all_warnings!
in top of your Podfile
.
If you want to disable / enable warnings for specific pods use :inhibit_warnings => true
or :inhibit_warnings => false
in the pod line. Then you should execute pod install
platform :ios
# ignore all warnings from all pods
inhibit_all_warnings!
# ignore warnings from a specific pod
pod 'Charts', :inhibit_warnings => true
Cocoapods Inhibit All Warnings Documentation
Related Topics
Uncaught Error/Exception Handling in Swift
Is Key-Value Observation (Kvo) Available in Swift
Swiftui Ios14 - Navigationview + List - Won't Fill Space
Formatting Input For Currency With Nsnumberformatter in Swift
Deinit Method Is Never Called - Swift Playground
How to Set Associated Objects in Swift
Swift - Resolving a Math Operation in a String
Load a Uiview from Nib in Swift
Overriding Superclass Property With Different Type in Swift
How to Get Ip Address in Swift
Uitableview With More Than One Custom Cells With Swift
Convert String to Date in Swift
Why Create "Implicitly Unwrapped Optionals", Since That Implies You Know There's a Value