Cannot implicitly convert type 'void' to 'System.Collections.IEnumerable' - ienumerable

Cannot implicitly convert type 'void' to 'System.Collections.IEnumerable'
This is my code below. I don't cant see why this is not working. I get this error above.
dgTimeSheets.DataSource = _DataViewSingleImport;

Related

Couldn't infer type parameter 'T'. when using Map.reduce(max)

I want to get the max value from a List. But since i migrated to null safety my code doesnt work anymore:
weightChart = [45.3, 21.5, 521.3];
weightChart.reduce(max)
I get the error:
Couldn't infer type parameter 'T'. Tried to infer 'double?' for 'T' which doesn't work: Type
parameter 'T' is declared to extend 'num' producing 'num'. The type 'double?' was inferred from:
Function type declared as 'T Function<T extends num>(T, T)' used where 'double? Function(double?,
double?)' is required. Consider passing explicit type argument(s) to the generic.
Let's try
import 'dart:math';
void main() {
List<double> weightChart = [45.3, 21.5, 521.3];
print(weightChart.reduce(max));
}

Using type as a value, why is the "self" keyword required here?

I'm currently learning type as a value in functions and wrote this sample code to play around:
import Foundation
class Animal {
func sound() {
print("Generic animal noises")
}
}
func foo(_ t:Animal) {
print("Hi")
}
foo(Animal) //Cannot convert value of type 'Animal.Type' to expected argument type 'Animal'
I'm not surprised by this result. Obviously you cant pass the type itself as an argument where an instance of that type is expected. But notice that the compiler says that the argument I passed was of type Animal.Type. So if I did this, it should compile right?
func foo(_ t:Animal.Type) {
print("Hi")
}
foo(Animal) //Expected member name or constructor call after type name
This is what really confuses me a heck ton, the compiler told me it was of type Animal.Type *but after making this change it once again shows an error.
Of course I listened to the fix Swift suggests and do:
foo(Animal.self) //Works correctly
But my biggest question is: WHY? Isn't Animal itself the type? Why does the compiler require me to use Animal.self to get the type? This really confuses me, I would like for some guidance.
Self-answering, with help of comments, I was able to find out the reason:
Using .self after the type name is called Postfix Self Expression:
A postfix self expression consists of an expression or the name of a
type, immediately followed by .self. It has the following forms:
expression.self
type.self
The first form evaluates to the value of the expression. For example, x.self evaluates to x.
The second form evaluates to the value of the type. Use this form to access a type as a value. For example, because SomeClass.self evaluates to the SomeClass type itself, you can pass it to a function or method that accepts a type-level argument.
Thus, the .self keyword is required to consider the type as a value capable of being passed as an argument to functions.

Unhandled Exception: type 'int' is not a subtype of type 'String'

I have this error : Unhandled Exception: type 'int' is not a subtype of type 'String' on this line of code :
double d=double.parse(map2["gain_gem"]);
map2["gain_gem"] is returned by php script api and return value 1
And after i try to do this :
globals.points = globals.points+d;
i have tried too :
globals.points = globals.points+double.parse(map2["gain_gem"]);
same problem
globals.points is defined as double in my script
double points=0;
You need to setup the int as a String first. The map2 value "gain_gem" is an int, that's where your error is coming from but to parse that value as a double it needs to be a String so if you toString the input it will be able to change it to a double. You should definitely make sure it will always be an int of course.
double d=double.parse(map2["gain_gem"].toString());
Documentation on toString()

Swift: Cannot convert value of type 'Int?' to specified type 'UInt32'

I'm trying to assign an array count to a UInt32. I get the error "Cannot convert value of type 'Int?' to specified type 'UInt32'". The array count is type Int, but the error says "Int?", which looks like an optional Int. I have no idea what else it could mean.
let randColorCount:UInt32 = slider?.randUIColors.count
I've also tried:
let randColorCount:UInt32 = UInt32(slider?.randUIColors.count)
But I get the error "Cannot invoke initializer for type 'UInt32' with an argument list of type '(Int?)'".
slider?.randUIColors.count results in Int? because of the use of the optional chaining.
One simple solution is to combine this with the nil coalescing operator ?? to provide a default value incase slider is nil.
let randColorCount = UInt32(slider?.randUIColors.count ?? 0)

Cannot use mutating member on immutable value of type [String]

I failed to append String by using following code:
(labGroups[labGroupIndex!].labs[labIndex!].tstDspGps[tstDspGpsIndex!].tests[testsIndex!]["specialReqValues"] as![String]).append("sdfsdf")
Error:
Cannot use mutating member on immutable value of type
'[String]'
And I can append value by using following code:
var arr = labGroups[labGroupIndex!].labs[labIndex!].tstDspGps[tstDspGpsIndex!].tests[testsIndex!]["specialReqValues"] as![String]
arr.append("testValue")
However, it only affect the variable arr.
That is not what I want, when I print:
((labGroups[labGroupIndex!].labs[labIndex!].tstDspGps[tstDspGpsIndex!].tests[testsIndex!]["specialReqValues"] as![String]))
it still has nil value.
Can anyone help to solve this problem?