yaml code: error = Can not evaluate YAQL expression [expression=$.svc.get("service-extension:l3vpn-svc").get("intent-type"), - workflow

error = Can not evaluate YAQL expression [expression=$.svc.get("service-extension:l3vpn-svc").get("intent-type"), error=No method "get" for receiver None matches supplied arguments, data={}]
error = Can not evaluate YAQL expression [expression=$.svc.get("service-extension:l3vpn-svc").get("intent-type"), error=No method "get" for receiver None matches supplied arguments, data={}]

Related

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

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)?

Unwrapping Optionals (Swift Playground)

Simple question for you folks about unwrapping optionals.
I've read and seen the multiple examples of unwrapping like the following
var strArray: [String]?
strArray = ["John", "Stacy", "Stephanie" ]
if let forSureNames = strArray{
for name in forSureNames{
print("\(name)")
}
} else{
print("Failed unwrapping")
}
However, My question is for if let forSureNames = strArray{...
When typing syntax similar to C++ (and from some swift examples), adding parenthesis
if (let forSureNames = strArray){
Gives the error codes:
'()' is not convertible to 'Bool'
error: MyPlayground.playground:13:4: error: expected expression in list of expressions
if(let forSureName = strArrays){
^
error: MyPlayground.playground:13:4: error: expected '{' after 'if' condition
if(let forSureName = strArrays){
^
Can anyone help explain the difference?
Edit
First time I asked a question on Stack overflow and feedback is awesome. I was trying to use a similar coding style to C++ due to my familiarity for an easy transition. However, you guys made it clear that it’s an incorrect approach. Thank you for a new and technical perspective towards unwrapping. Cheers!
As you know, () can be used to surround an expression and it will have no effect on the evaluation of that expression, and you are asking "why can't I do the same to let forSureNames = strArray?" Right?
This is because let forSureNames = strArray is not an expression. You are parsing this statement wrong. The word let is part of the if let statement.
You are confusing if let statements with C-style if statements, where after the if, there is always an expression that evaluates to Bool. if let simply does not work like that. It takes the form:
if let <identifier> = <expression> { }
where expression must evaluate to an optional type. So putting () around let <identifier> = <expression> makes little sense. You could put () around strArray because that is an expression, but I don't see the point of that.
if (let forSureNames = strArray) {
... this is trying to use optional binding. Optional binding allows you to safely unwrap some optional constant/variable which can be nil. If this value is assigned, it satisfies the if statement with this unwrapped (non-optional) constant/variable.
But, it doesn't work with parentheses, since values coming from parentheses have to be of type Bool. An optional binding doesn't return a Bool value directly, it just attempts to assign the constant/variable and implicitly returns a boolean based on whether the assignment occurred.
if (true) {...} // works
if (let value = optional) {...} // doesn't work
So, you have to remove these parentheses
if let forSureNames = strArray {...}
Unlike other languages, conditions in Swift don't have to be inside parentheses and it is recommended not to use them if they aren't required.
Swift is vastly different from C++, so you shouldn't be surprised that C++ syntax doesn't work in Swift.
There are two type of if statements in Swift: the type that takes an expression (if foo.bar), and the type that does pattern matching (if let foo = bar, if case .some(let foo) = bar, etc).
Because Swift supports parenthesized expressions, if foo.bar works the same as if (foo.bar): in the first case, the condition is foo.bar, and in the second case, the condition is (foo.bar). In other words, the parentheses here are part of the condition expression, not part of the if statement. This contrasts with C++, where the parentheses are part of the if statement. In both cases, however, you can add as many parentheses as you want: if (((((((((foo.bar))))))))), though silly, is superficially valid in both languages.
Recall that you can wrap arbitrary expressions in parentheses, but you can't just wrap anything in parentheses. You wouldn't write (if foo.bar) in Swift or C++, because you know that if isn't an expression. Then, the same applies to let foo = bar. It's not an expression either, so you can't wrap it in parentheses. if let foo = bar is fine, but if (let foo = bar) isn't.
C++ supports a similar syntax in some cases:
if (auto foo = make_unique<int>(3)) { ... } else { ... }
This syntax declares foo and tests it (using its operator bool()), and then branches the program appropriately. Since the condition is a declaration statement, not an expression, it can't be wrapped in more parentheses either: if ((auto foo = make_unique<int>(3))) is a compile-time error, just like if (let foo = bar) in Swift.
Can anyone help explain the difference?
The difference is that Swift is not C++. Although they are similar in many ways, they have different grammars. The grammar defines (in part) the language's syntax.
In C++, an if statement is part of the selection-statement production in the grammar:
selection-statement:
if ( condition ) statement
if ( condition ) statement else statement
switch ( condition ) statement
So the parentheses around the condition of the if statement are part of the if statement, and not part of the condition.
In Swift, an if statement is the only production of the if-statement production in the grammar:
if-statement → if condition-list code-block else-clauseopt
Note that there are no parentheses directly in the if-statement's production. So if there are to be parentheses, they must be part of the condition-list production. Here's how condition-list is defined:
condition-list → condition | condition , condition-list
condition → expression | availability-condition | case-condition | optional-binding-condition
So a condition-list is one or more conditions, separated by commas. If you click through each of the four alternatives in condition, you'll find that availability-condition must start with the token #availability, case-condition must start with the token case, and optional-binding-condition must start with either the token let or the token var. None of those three productions can start with a parenthesis token.
The only production of condition that can start with the token ( is the expression production, and an expression production cannot have the token let after the token (.

How do I set a conditional breakpoint based on a generic type?

Is there any way to set a breakpoint as pictured below?
I'd like the breakpoint to trigger when Element is type ProjectEntity, but I get the following error:
Stopped due to an error evaluating condition of breakpoint 13.1: "Element == ProjectEntity"
Couldn't parse conditional expression:
error: <EXPR>:3:1: error: use of unresolved identifier 'Element'
Element == ProjectEntity
^~~~~~~
I also can't po Element when that breakpoint is hit. Any idea why?
Normally, in swift code, you can add .self after a type to get the Type object that represents the type.
So,
Element.self == ProjectEntity.self
However, the runtime does not seem to recognise any generic type parameters, so I suppose you cannot check for such a condition at runtime.
This means that you must get something that is of type Element and check that against ProjectEntity with is.
someElement is ProjectEntity
I ended up creating a local variable that assigned to the generic type, and then calling type(of:) on that and checking it against the type I wanted to break on.
let e = Element.self
let isProject = type(of: e) == ProjectEntity.Type.self
Then I made the condition for the breakpoint isProject.

How to use max with swift3?

i am getting an error for the bellow code:
var bubbleWidth:CGFloat!
bubbleWidth:CGFloat = max( CGFloat(15) , bubbleWidth )
here is the error message:
no candidates produce the expected contextual result type 'cgfloat!'
this code was working without any problem on swift 2 , i don't know why i am getting that error now !
EDIT:
here is my real code:
var bubbleWidth:CGFloat!
bubbleWidth = imageView.frame.width + 11
bubbleWidth = max( CGFloat(15) ,
bubbleWidth )
and here is the error that i am receving:
Edit:
please note: i don't want to assign value to bubbleWidth, like that
var bubbleWidth:CGFloat = -1
Thanks
This is a consequence of SE-0054 Abolish ImplicitlyUnwrappedOptional type which has been implemented in Swift 3:
However, the appearance of ! at the end of a property or variable declaration's type no longer indicates that the declaration has IUO type; rather, it indicates that (1) the declaration has optional type, and (2) the declaration has an attribute indicating that its value may be implicitly forced. ...
If the expression can be explicitly type checked with a strong optional type, it will be. However, the type checker will fall back to forcing the optional if necessary.
Now one could argue that the compiler should fall back to unwrapping
the optional in
bubbleWidth = max(CGFloat(15), bubbleWidth)
but for some reason that works only with a float literal
bubbleWidth = max(15, bubbleWidth)
and I am not sure if this is a bug or not. Alternatively, unwrap the value explicitly
bubbleWidth = max(CGFloat(15), bubbleWidth!)
or – better – provide a default value with the nil-coalescing operator ??:
bubbleWidth = max(CGFloat(15), bubbleWidth ?? 0)

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
}