The output expects a value of type "string" but the provided value is of type "null | string" - azure-bicep

What is the difference between these two outputs?
resource endpoint 'Microsoft.Network/privateEndpoints#2020-11-01' = {
name: name
location: platform_location
}
output dnsRegionIpAddress string = first(endpoint.properties.customDnsConfigs[0]).ipAddresses)
output dnsRegionIpAddress string = endpoint.properties.customDnsConfigs[0].ipAddresses[0]
Recently i had to remove first(..) because it kept giving me syntax error The output expects a value of type "string" but the provided value is of type "null | string" is there a downside using array[0] insted of first(array)?

Related

Swift "change an item in an array" Noobie in swift

how can i change an item in an array (Cannot convert value of type 'Int' to expected argument type 'String')
var headersSend: HTTPHeaders = [
"changeMe": "none",
"Accept": "application/json"
]
headersSend[0] = "changeMe" : "Changed!" // <--- ? Cannot convert value of type 'Int' to expected argument type 'String'
headersSend is a dictionary, not an array. It stores key-value pairs, where key and value are both of type String.
Accessing through headersSend[0] means you want to change item at key 0. You have a compilation error because dictionary's key is not of type Int. You have to use String key instead.
That's the way we change value at specific key
dictionary[key] = newValue
In your case it would be
headersSend["changeMe"] = "Changed!"
I suggest you to read more about collection types here.

Replace "," in PSCustomObject's properties while retaining the object type

I have the following sample code which replaces all comma values (,) with a period (.):
$foo = [PSCustomObject]#{
Num1 = "0.11"
Num2 = "0,12"
}
Write-Host "Type before:" $foo.GetType().FullName
$foo = $foo -replace(",",".")
Write-Host "Type after:" $foo.GetType().FullName
It produces the following output:
Type before: System.Management.Automation.PSCustomObject
Type after: System.String
I'd like to retain the PSCustomObject type and not have it converted to a string. Any ideas on how to accomplish this aside from:
$foo.Num2.Replace(",",".")
I'd prefer not to get into listing out each property with a replace statement as my real code has MANY properties in this object.
PowerShell comparison operators (including the replacement operator) implicitly convert the first operand to a type that matches the second operand. In your case that is transoforming the custom object to a string representation of itself.
To replace something in the properties of your object: enumerate the properties and do the replacement operation on the actual properties, not the object as a whole.
$foo.PSObject.Properties | ForEach-Object {
if ($_.Value -is [string]) {
$_.Value = $_.Value.Replace(',', '.')
}
}

error: cannot convert value of type 'String' to expected argument type 'Character'

I am running into this error using Swift 4. I'm attempting to get the index of an element in an array.
if removedLetters.contains(selectedLetter!) {
print("\(selectedLetter!) is in the word")
print(theWordArray.index(of: "\(selectedLetter)"))
}
results in error: cannot convert value of type 'String' to expected argument type 'Character'
I also tried creating a character variable var selectedChar:Character = selectedLetter but I get a conversion error: error: cannot convert value of type 'String?' to specified type 'Character'
You can convert a String to a Character by accessing the first letter if you are confident that selectedLetter is one letter.
if removedLetters.contains(selectedLetter!) {
print("\(selectedLetter!) is in the word")
print(theWordArray.index(of: "\(theWordArray[selectedLetter!.first!])")
}
If it is more than one letter, your code will crash though, so do some validating first.

Swift - Binary operator '>=' cannot be applied to operands of type 'String' and 'Int'

Not really understanding why this isn't working. I'm pretty new to the Swift world.
The error I'm getting is Binary operator '>=' cannot be applied to operands of type 'String' and 'Int'
Could anyone help me understand why I'm getting this error? Do I need to convert the String to a Double or is there something else I'm totally missing? Again I'm new to Swift.
Do I need to convert the String to a Double?
Yes, that's basically it.
You must declare first a variable to accumulate all the inputs:
var inputs = [Double]()
Observe that I'm declaring an array of Double because that's what we are interested in.
Then, each time you ask the input, convert the obtained String to Double and store it in your array:
print("Please enter a temperature\t", terminator: "")
var message : String = readLine()!
let value : Double = Double(message)!
inputs.append(value)
Finally, check all the accumulated values in inputs (you got this part right):
for value in inputs {
// value is already a Double
if value >= 80 {
message = "hot!"
}
// etc.
}
I suggest researching how to convert to Double with error checking (i.e. how to detect "100 hot!" and ignore it because can't be converted).
Also, consider using a loop to read the values.

Swift: Trying to print an empty string – The process has been returned to the state before expression evaluation

I have a model with a column entry, which is a String. Sometimes entry has some text in it, sometimes it doesn't and it's an empty string.
When I try to print the string in console, I'm getting The process has been returned to the state before expression evaluation. (running e object.entry)
Not sure why it isn't just printing ""
Trying e object.entry! gives me error: operand of postfix '!' should have optional type; type is 'String'
Any ideas on how to fix this?
Empty String "" doesn't mean nil, and entry is not an optional type.
I think you are supposed to declare entry as "" when initialize the object
class object {
var entry = ""
//do anything you want next
}