Cannot invoke initializer for type 'Double' with an argument list of type '(String?)'
amount?.count <= 0
here amount is optional. You have to make sure it not nil
.
let amount:String? = amountTF.text
if let amountValue = amount, amountValue.count <= 0 {
}
amountValue.count <= 0
will only be called if amount
is not nil.
Same issue for this let am = Double(amount)
. amount
is optional.
if let amountValue = amount, let am = Double(amountValue) {
// am
}
Error Cannot invoke initializer for type 'String' with an argument list of type '(Int64?)' with nil-coalescing operator
You can simply do,
let int64Value: Int64 = 123
let str = String(int64Value)
Edit:
Since detailItem?.count
is optional
, you need to unwrap it before passing it to the String
initializer. You can use nil coalescing operator to unwrap and provide a default value, i.e.
cell.textLabel?.text = String(detailItem?.count ?? 1)
Cannot invoke initializer for type 'String' with an argument list of type '(Int?)'
Update
cell.orderprice.text = String(model.price)
with
if let priceOfProduct = model.price {
cell.orderprice.text = String(priceOfProduct )
}
else{
cell.orderprice.text = "";
}
SWIFT 4.1 Cannot invoke initializer for type 'Double' with an argument list of type '(String?)'
The error in the topic says that you can't create a Double from an optional String which is true.
To solve it force unwrap the values for Latitude
and Longitude
.
But the main issue is a scope issue, all variables used in the initializer must be in the same scope. You can flatten the scope with guard
statements:
...
databaseHandle = ref?.child("Community").child("Alert Notifications").observe(.childAdded, with: { (snapshot) in
defer { self.dummyFunctionToFoolFirebaseObservers() }
guard let data = snapshot.value as? [String:String] else { return }
guard let firebaseKey = snapshot.key as? String else { return }
// let date = data!["Date"]
// let time = data!["Time"]
let dataLatitude = data["Latitude"]!
let dataLongitude = data["Longitude"]!
self.alertIconToDisplay = data["Description"]!
let doubledLatitude = Double(dataLatitude)
let doubledLongitude = Double(dataLongitude)
let recombinedCoordinate = CLLocationCoordinate2D(latitude: doubledLatitude!, longitude: doubledLongitude!)
print("Firebase post retrieved !")
// self .keyaLon = dataKey
// self.keyaLonArray.append(firebaseKey)
print("Longitude Actual DataKey is \(String(describing: firebaseKey))")
print("fir long \((snapshot.value!, snapshot.key))")
self.userAlertAnnotation = UserAlert(type: self.alertIconToDisplay, coordinate: recombinedCoordinate, firebaseKey: firebaseKey)
self.mapView.addAnnotation(self.userAlertAnnotation)
})
Cannot invoke initializer for type 'Double' with an argument list of type '(RangeDouble)'
The type of the in
parameter in a loop must be a range of Int
. Besides you cannot convert a range to a single type like Double
To iterate over a sequence != Int
you need stride
let distance = 25.0
for dista in stride(from:0.0, to: distance, by: 1.0) {
print(dista)
}
Related Topics
How to Open a Link to a PDF with Wkwebview
Uitableviewcell Without Using Deprecated Method Initwithframe:Reuseidentifier
How to Resize Views When Keyboard Pops Up Using Auto Layout
Swiftui How to Align a View That's Larger Than Screen Width
Accessibility for iOS, Voiceover Read Order Issue
Ios7 - Device Unique Identifier
How to Find Out What View a Touch Event Ended At
Clip Image to Square in Swiftui
Perform Segue from App Delegate Swift
Getting Random "Facebookerrdomain Error 10000"
Share Datas Between Two Apps with iOS 8 App Groups (Using Nsuserdefaults)
Will Push Notification Still Work After Ownership Transfer in Itunesconnect
Dyld: Library Not Loaded for a Framework Within a Framework
Custom Scenekit Geometry in Swift on iOS Not Working But Equivalent Objective C Code Does
"Could Not Inspect Application Package" Xcode
iOS Are Methods Called by Delegates and Observers Executed on the Main Thread