Using '!' here is deprecated and will be removed in a future release - swift 4.2
Use this code : cell. img!.sd_setImage(with: url! as URL, completed: block_image)
Suggestion: use URL
instead of NSURL
let url = URL(string: "" ) //use url String
cell.img!.sd_setImage(with: url, completed: block_image)
Problem Using '!' will be removed in a future release
Just use
if let encodingName = response?.textEncodingName as? CFString , convertedEncoding == nil {
convertedEncoding = String.Encoding(rawValue: CFStringConvertEncodingToNSStringEncoding(
CFStringConvertIANACharSetNameToEncoding(encodingName)))
}
The issue is caused by casting to CFString!
Trying to understand this warning:[UITabBarItem]! Using '!' here is deprecated and will be removed in a future release
I made sure that there would not be a crash by adding a guard:
override func viewDidLoad() {
super.viewDidLoad()
guard let items = self.tabBar.items else { return }
for item in items {
if let image = item.image {
item.image = image.imageWithColor(tintColor: self.normalTint).withRenderingMode(UIImageRenderingMode.alwaysOriginal)
}
}
}
Error with Spring deprecation in future releases of Swift 4.2
The solution it's pretty simple:
1. Forced unwrapping or forced up and downcasting is really really unsafe, probably this is the reason Apple is removing it.
var tabBarItems = self.tabBar.items as [UITabBarItem]!
change it for:
var tabBarItems = self.tabBar.items as [UITabBarItem]?
but tabBarItems can be nil, so I recommend a guard or something like that.
guard var tabBarItems = self.tabBar.items as [UITabBarItem]? else { return }
example code:
class C1 {
}
class C2: C1 {
}
let cc2 = C2()
var firstSelectedImage: UIImage? {
didSet {
if let image = firstSelectedImage {
guard var tabBarItems = cc2 as C1? else {return}
print(tabBarItems)
}
}
}
init' is deprecated warning after Swift4 convert
With Swift 4.2 and Swift 5, you can choose one of the 5 following solutions in order to solve your problem.
#1. Using NSNumber
's intValue
property
import Foundation
let integer = NSNumber(value: false).intValue
print(integer) // prints 0
#2. Using type casting
import Foundation
let integer = NSNumber(value: false) as? Int
print(String(describing: integer)) // prints Optional(0)
#3. Using Int
's init(exactly:)
initializer
import Foundation
let integer = Int(exactly: NSNumber(value: false))
print(String(describing: integer)) // prints Optional(0)
As an alternative to the previous code, you can use the more concise code below.
import Foundation
let integer = Int(exactly: false)
print(String(describing: integer)) // prints Optional(0)
#4. Using Int
's init(truncating:)
initializer
import Foundation
let integer = Int(truncating: false)
print(integer) // prints 0
#5. Using control flow
Note that the following sample codes do not require to import Foundation.
Usage #1 (if statement):
let integer: Int
let bool = false
if bool {
integer = 1
} else {
integer = 0
}
print(integer) // prints 0
Usage #2 (ternary operator):
let integer = false ? 1 : 0
print(integer) // prints 0
Build input file cannot be found' Swift 4.2, Xcode 10.0
Moving the folders around the inspector can cause the error "Build input file cannot be found"
SWIFT 5
In Swift 5, the error came up but the identity showed no errors.
- Go under build settings and select packaging.
- Delete the current paths for Debug and Release and enter your new path where the info.plist is kept.
For example [APPROJECTNAME]/[THEINFOPLISTFOLDER]/info.plist
In the screenshot below, the path is API-client/Resources/info.plist
SWIFT 4
To fix it, go to the general tab and under identity reselect the info.plist that you like
Suppressing deprecated warnings in Xcode
Try -Wno-deprecated-declarations
, or its corresponding setting in Xcode, GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS
(pro tip: just type in "deprecated" in the build settings to find the specific setting for this warning).
Current versions of Xcode (e.g. Xcode 9.2):
Ancient versions of Xcode (e.g. Xcode 2.x, 3.x):
Related Topics
Swiftui - How to Blur the Default Background Color of a View
Call Extensiondelegate to Create/Refresh Data for Complication
What Is The Purpose of Launch Images in an iOS Application
Left-To-Right Mark Not Working in Swift
Firebase Cloud Messaging Cannot Parse Topic Name
"Googleplus/Googleplus.H File Not Found" When Trying to Build My Project
iPhone - Memory Leak - Nsdata Datawithcontentsofurl & UIwebview
Get Path to Subdirectory in Resources Folder
Uitableviewcells Initial Load View/Display Issue
iOS UIlabel Autoshrink So Word Doesn't Truncate to Two Lines
How to Enable/Disable Onetimecode Feature for Specific Text Field
Value of Type 'string' Has No Member 'stringbytrimmingcharactersinset'
iOS Where to Put Custom Cell Design? Awakefromnib or Cellforrowatindexpath
Are Private Frameworks Supported on iOS
Determine The Maximum Number of Characters a UIlabel Can Take
Get All Ranges of a Substring in a String in Swift