Swift UI Xcode 11 beta 5 - Error when building - swiftui

I'm having this error 'The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions' every-time I try to build my app and every-time I build the error is in a different view and in different parts of the code.
Normally it shows where I have a ForEach or a .sheet Presentation but there are views that have them and they don't give an error.
This only happened when I updated to xCode 11 beta 5, is anyone with the same error?
Already tried to replace the ForEach and .sheet on the views but there are views that have ForEach and they don't give an error and they exactly the same.
The expected result is not having that error when compiling, but for some reason it always shows: 'The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions'

I had that problem, and it is documented in the last release notes (beta 5):
Using a ForEach view with a complex expression in its closure can may
result in compiler errors. Workaround: Extract those expressions into
their own View types. (53325810)
When you get the The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions error, ignore all other errors, as they cannot be trusted. First you need to address the "reasonable time" problem.
You need to encapsulate the contents of the ForEach, and it will most likely go away.

Related

Unable to infer complex closure return type with SwiftUI

Following part 3 of Apple's tutorial on SwiftUI, Handling User Input, I get this error:
Unable to infer complex closure return type; add explicit type to disambiguate
I'm using the same code as the tutorial (even coping from the 'Complete' sample code doesn't resolve the error).
Does anyone have a cue what is going wrong here?
struct LandmarkRow: View {
var landmark: Landmark
var body: some View {
HStack {
landmark.image(forSize: 50)
Text(verbatim: landmark.name)
Spacer()
if landmark.isFavorite {
Image(systemName: "star.fill")
.imageScale(.medium)
}
}
}
}
Regardless of the cause of the issue, how could you indeed add an explicit type to disambiguate here? What would the return type in such a case be?
--
Update
Apparently you should not continue with your result of the 2nd tutorial with the 3rd. Some things changed in between of the tutorials that is not documented in the tutorial. I've added the project files to Github so you can check out the diff.
It's better to start the 3rd tutorial fresh with a fresh download of the Project files of the 3rd tutorial.
The issue is not with the closure, but with the isFavorite property on landmark.
It is not declared on the Landmark type, and the compiler instead of showing the undeclared property error, unable to resolve the stacks build closure return type, so it shows and error there.
Great job Apple tutorial writers and even better one Xcode11 compiler.
To fix:
Declare isFavorite variable on the Landmark type.
Make sure you update the landmarkData.json for every landmark record with the isFavorite = false entry, otherwise the app will crash at runtime.
Some background to this problem
Like #dirtydanee already answered there is a difference between those two tutorials. But the problem behind the problem is that while it looks like you're doing a configuration it's actually just functions nested in functions using generics and protocols to "magically" parse everything into a compiling function.
However conformance to these generics and protocols need to be pretty precise because if not the whole tree of functions cannot compile anymore. But it's hard to determine for the compiler what conformance actually failed. This is why you see an error at the top rather than at the point where it actually happens.
It's strongly advised to make sure your views are decomposed into natural and simple blocks so you're not pouring over hundreds of lines of View code to find that one bug.
Dave DeLong had a really great talk about how to compose Views from ViewControllers that still holds true until today: basically you never use View as a subview inside another View but you need to decompose your View of many, simple Views. Otherwise these errors'll drive you nuts.
For people getting this error on SwiftUI and looking for a way to debug their view stack
This error happens mainly when there is a compilation issue on one child View.
1 - Make sure your parent view can support multiple subviews (VStack, ZStack) and you have less than 10 subviews. Sometime you may want to add a Group wrapper.
2 - If this is not the problem, there is probably an issue with one subview. Try to isolate the one you suspect to have the issue. Usually I copy the subview into a property and a different error appears
var debug: some View {
MyViewWithError(property: self.property)
}
Most of the time you'll encounter this because you pass the property (self.property) instead of a binding (self.$property)
Hope this can help some people
I have run into this error when made a typo. Also this error appears when a code has syntax issues. Just check if your changes are correct
I encountered the problem in a subview where a #Binding prop was of a different type of the #Binding source.

Catch url without parameters

I'm having issues catching url while excluding parameters (what's after ? sign)
So for the following links
/alfa/wp-includes/js/jquery/jquery.js
/beta/wp-includes/js/jquery/jquery.js?parameter=value
I need the following
alfa /wp-includes/js/jquery/jquery.js
beta /wp-includes/js/jquery/jquery.js
So far I came up with the following but it always catch full link including parameters, which I don't need
^(/alfa|beta)?(/wp-(content|admin|includes).*)
Try this (assuming your inputs always ended in .js)
(/(alfa|beta)(/wp-(content|admin|includes).*))(\.js|\?)
Or improving upon ctwheels' comment:
^/(alfa|beta)([^?\s]*)(\.js|\?)
I'm not sure if it's 100% what you need but I ran that query in regexpal.com and it works as you described.
Try this :
(\/(alfa|beta)[^\?]+)
https://regex101.com/r/AmgHTS/8

Viewstate Replacing error. [ViewStateException: Invalid viewstate. ]

Tried with JMeter: How to know why my regular expression extractor in JMeter is not extracting the data but still not able to replace my view-state, its throwing [ViewStateException: Invalid viewstate. ] error . Please check the attachment , an my script has not _EVENTVALIDATION .
enter image description hereViewstate
viwstate2
As i am observing from your attached image
You need to pass same `Reference name` as a value of __VIEWSTATE in Next request
First Cross verify, Is your correaltion is correct or not? (you can use debug sampler to check the correlation)
If yes, then first mistake is, you had given reference name as "VIEWSTATE" in below shown snapshot
But you are passing ${jsfViewState} in other snapshot, so correct it and pass same reference name i.e. ${VIEWSTATE}
It'll resolve your issue, if issue still persists then click on encode button beside Name-Value pair because sometimes there is some mismatch in encoding format between the response which we capture and the value which we have to pass
Don't be confused with ASP.NET ViewState and JSF Viewstate, they have similar nature but different underlying technologies and different parameter names
Given you correctly correlated the value, I believe you need to change __VIEWSTATE parameter name to javax.faces.ViewState and it should work.
See Testing a JSF Application with JMeter guide for a little bit more detailed explanation on the topic and How to debug your Apache JMeter script guide for some troubleshooting techniques.

Suppress F# Compiler Warning: Possible incorrect indentation: this token is offside of context

I have some xunit tests I would like to layout as follows for readability:
[<Fact>] let ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2
[<Fact>] let ``ToString yields two``() = target.ToString().ShouldBe "two"
[<Fact>] let ``Has underlysing type int``() = target.GetUnderlyingType().ShouldBe typeof<int>
I'm getting a compiler warning on the let statements: "Possible incorrect indentation: this token is offside of context started at position %s. Try indenting this token further or using standard formatting conventions."
I tried #nowarn "lexfltTokenIsOffsideOfContextStartedEarlier" but that just generated another compiler warning "Invalid warning number".
There isn't a warning number listed for this error in https://github.com/fsharp/fsharp/blob/057dbf77df7355321c3c18137c2d552bdfa1272b/src/fsharp/FSComp.txt
Is there a way to suppress this warning?
I apologize for answering in a style, "you don't need it", but this seems to be the case. Also, this question apparently becomes a FAQ for those who write Unit Tests in F#. Yet another case is for [<Literal>]'s.
Anyway, disabling warnings on a project- or even file-level seems to be a bad idea, unless you have a good reason to do that.
As far as I understood, you'd like to have the statements to be one-liners (e.g., [<Fact>] did not occupy an entire line). There are two ways to accomplish that in VS2013:
Place the attribute inside let:
let [<Fact>] ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2
Write a double-semicolon after the declaration:
[<Fact>] let ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2;;
Try this:
#nowarn "0058"
To find out what the correct warning number is, just build the thing in command line (or in VS and then go to View -> Output -> Build), it will tell you. Here is what I see:
Program.fs(7,3): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (5:25). Try indenting this token further or using standard formatting conventions.

Powershell Get-WebVirtualDirectory : Specified cast is not valid

I've narrowed my code down to this-
Function Check-VirtualPhysicalPath{
Param([Parameter(Mandatory=$True)] [AllowEmptyString()][String]$Page)
#This creates an arraylist of items that are our virtual/physical paths
$WebVD= Get-WebVirtualDirectory
}
when I run this script in a function setting the results of 'Get-WebVirtualDirectory' returns a casting error. This has me baffled because when i try to run the line
$WebVD= Get-WebVirtualDirectory
in either a script or merely on the console there are no errors returned and i can access the variable and the data is correct. What am I doing wrong?
Now as a side-note this is merely the problematic code so i'm not including everything, but even when i comment everything else out i end up just running what you see here with problems just the same.
i'm calling the code with this in a separate script
$page = [string]$(gc "C:\page.txt")
. C:\VP.ps1
$(Check-VirtualPhysicalPath($page))
Powershell is reacting like i'm casting the $WebVD variable, I'm not sure if this is a bug or if i'm missing something entirely...
Edit:
it looks like i forgot to pull out that part of the code. I'm code crawling, the point of the hashtable is that i'm storing the number of times a resource is used in a hash table with the key being the file name and the value how many times it has been used so i use regular expressions to determine that. My question is unrelated to my other code because it's having problems even when my code only contains what you see above.