If I run this code:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
Text("Text")
.navigationTitle("My Title")
}
}
}
I get these warnings while debugging with my iPhone:
2021-03-15 18:00:08.023556+0100 Trial2[373:7602] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x283874dc0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x103817930]-(6)-[_UIModernBarButton:0x102f2e3d0'My Title'] (active)>",
"<NSLayoutConstraint:0x283874e10 'CB_Trailing_Trailing' _UIModernBarButton:0x102f2e3d0'My Title'.trailing <= BackButton.trailing (active, names: BackButton:0x102f2d9a0 )>",
"<NSLayoutConstraint:0x283875b30 'UINav_static_button_horiz_position' _UIModernBarButton:0x103817930.leading == UILayoutGuide:0x282245f80'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x283875b80 'UINavItemContentGuide-leading' H:[BackButton]-(0)-[UILayoutGuide:0x282245ea0'UINavigationBarItemContentLayoutGuide'] (active, names: BackButton:0x102f2d9a0 )>",
"<NSLayoutConstraint:0x283858b90 'UINavItemContentGuide-trailing' UILayoutGuide:0x282245ea0'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x102f220c0.trailing (active)>",
"<NSLayoutConstraint:0x283876300 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x102f220c0.width == 0 (active)>",
"<NSLayoutConstraint:0x283858a00 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x282245f80'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UINavigationBarContentView:0x102f220c0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x283874dc0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x103817930]-(6)-[_UIModernBarButton:0x102f2e3d0'My Title'] (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
I've seen a similar question here, but the problem was that .navigationBarTitle is deprecated. In my case I'm using .navigationTitle. Is it also deprecated (I doubt it as the documentation doesn't say that)? Am I using it in a wrong way? Is it a bug of Xcode? Or simply is this normal and I shouldn't worry about these warnings?
P.S.: I'm new to Swift and SwiftUI programming
EDIT: #Andrew found something that seems to solve the issue (adding the modifier .navigationViewStyle(StackNavigationViewStyle()) to NavigationView). Yet, I don't understand if this is the right solution for a well defined issue in my code, or a trick to workaround an Xcode false positive/bug.
I would like someone to explain me why this code seem to fix my issue.
I don't think that .navigationViewStyle(StackNavigationViewStyle()) is the right solution, because the issue happened while following the Apple's tutorial. I think that if the error were expected, Apple would know it and put this line in the tutorial. So it is easier for me to believe it is an Xcode 14 bug.
To recap, my questions are:
Is the warning fired by Xcode expected? Or is it a bug?
Why .navigationViewStyle(StackNavigationViewStyle()) fixes the issue?
When is this warning really an issue? (I can't see anything wrong when I run it)
Related
My stepper is defined as follows (Standalone WatchOS app)
Stepper(value: $myCount) {
Text("\(myCount)").font(.footnote).accessibilityIdentifier("count_label")
}.accessibilityIdentifier("my_stepper")
It is fully functional on the real / simulator devices. During a test case, defined below, I am unable to invoke the increment button. (I get an error and the button itself is not hittable, ever)
XCTAssertTrue(app.steppers["my_stepper"].waitForExistence(timeout: 10))
XCTAssertFalse(app.steppers["my_stepper"].buttons["Remove"].isEnabled)
XCTAssertTrue(app.steppers["my_stepper"].buttons["Add"].isEnabled)
-> (Error) app.steppers["my_stepper"].buttons["Add"].tap()
Error kAXErrorCannotComplete performing AXAction
kAXScrollToVisibleAction on element AX element pid
I tried to forceTap (using coordinates) with no luck. Any idea how to invoke the increment action?
While the increment and decrement buttons exist in the view stack, they are not hittable. Likely a bug in SwiftUI that impacts either WatchOS or all platforms. Best way I have found to temporarily get past the issue is using the following tutorial :
app.steppers["my_stepper"].coordinate(withNormalizedOffset: CGVector(dx: 0.9, dy: 0.5)).tap()
This is a workaround that will probably fail on different devices. For me, it would only work with Ultra 49mm watchOS 9.0. Accepting this until a better answer is found.
When I go to view my SwiftUI through the canvas preview in Xcode 11.3.1 I am getting the error
Compiling failed: 'Color' is only available in iOS 13.0 or newer
But the project itself builds successfully and the simulator loads without any issues. I have tried clearing the build folder, quitting Xcode and rebuilding but still no luck.
Any help would be great. Thanks in advance.
SwiftUI minimum deployment target is 13.0, so if you have project with support of older version, then all SwiftUI code (including preview providers) you have to prepend with availability modifier, like
#available(iOS 13.0, *) // << here !!
struct Demo: View {
var body: some View {
VStack {
Text("Hello")
}
}
}
You Should use Assets or Other option like Color Literal for Color.
Don't use the system Color option since your deployment target is 11.4.
Man, I've had a similar issue. The problem was that sometimes my preview worked sometimes it didn't... I reviewed the diagnostics and realized that there are some #_dynamicReplacement attributes mentioned (which are used, I guess, for hot reloading). It wasn't working when I've had a file with #available attributes opened in the (adjacent) editor. When I closed that editor everything worked back again.
Magic ✨
Also one more hint from my friend - when you have a file from another target (not the one hosting your Canvas-related code) in (adjacent) editor it behaves the same way.
I am trying to iterate through an array of objects. This object is conforming to the Identifiable protocol. When using a ForEach loop, I get the following error: Type of expression is ambiguous without more context
I've included the block of code that is throwing the error. The error is specifically underlining \.name. Am I missing something?
Another note: This code worked in Xcode 11 Beta 2 but broke in Xcode 11 Beta 3...
struct ItemRow : View {
var categoryName:String
var items:[Item]
var body: some View {
VStack {
Text(self.categoryName)
.font(.title)
ScrollView(showsHorizontalIndicator: false) {
HStack (alignment: .top){
ForEach (self.items.identified(by: \.name)) { item in
NavigationLink(destination: ItemDetail(item: item)) {
ItemView(item: item)
.frame(width:300)
.padding(.trailing, 30)
}
}
}
}
}
}
}
Here is the Identifiable Object:
struct Item:Hashable, Codable, Identifiable {
var id:Int
var name:String
var category:Category
var description:String
}
(This code has been abstracted)
The first thing you need to know, is that when building views, compile errors can be very misleading. An error may show at the bottom of your code, but the cause may be at the top. I expect this will be fixed sometime in the future, but for the time being, you need to be careful.
Your code compiles just fine. Because of what I said about misleading errors, one brute but effective technique to debug the problem, is to start commenting bits of code until the error goes away. This will let pin point where the root of the problem may be.
A good way of updating your question is including enough code, so that people can reproduce the problem just by copy and paste into their own Xcode. It may be a lot of work for you, but I found that most of the time, you understand the problem during that process and you may not even need to post the question in the first place. Reducing an issue to its minimum expression, is also a great way of understading/fixing a problem.
UPDATE
Since you added more code, the error is showing where you would have not expected:
The ScrollView initialiser you were using, was deprecated. It now looks like this:
ScrollView(.horizontal, showsIndicators: false)
Also something that may potentially be a problem. You are using:
self.items.identified(by: \.name)
But don't you mean:
self.items.identified(by: \.id)
If so, then you do not need to use identified, since Item is already Identifiable and as such, it is already identified by id.
self.items
The issue was actually with the following line:
ScrollView(showsHorizontalIndicator: false)
ScrollView doesn't work like that anymore in Beta 3. The arguments now look something like this:
ScrollView(.horizontal, showsIndicators: false)
That will give you a horizontal scrolling view and will not show the scrolling indicators.
I do have a strange issue in using the reorder feature in my app's UICollectionView. We have a custom layout which is implemented to show a decoration view. The collection view uses a flow based layout. When I move the first cell from its position to last cell position for reordering of the cells, the app crashes before it calls the collection view delegate's collectionView(moveItemAt: to) method.
Attached the stack trace of this issue. You can see that crash is happening in the bridging between NSIndexPath and IndexPath. I am not sure why it is happening inside UIKit. Searching for this issue found that it appears to be bug inside UIKIt which got introduced in Swift 3.0. I tested my old build which was built before swift 3.0 migration and it works without any crashes.
Can someone tell me how can I fix this issue?
Related bugs links
UICollectionView broken after Swift 3 migration?
https://bugs.swift.org/browse/SR-2103
https://bugs.swift.org/browse/SR-2417
func handleLongGesture(_ gesture: UILongPressGestureRecognizer) {
switch(gesture.state) {
case UIGestureRecognizerState.began:
if let movingPageIndexPath = collectionView.indexPathForItem(at: gesture.location(in: collectionView)) {
collectionView.beginInteractiveMovementForItem(at: movingPageIndexPath)
}
case UIGestureRecognizerState.changed:
collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: collectionView))
case UIGestureRecognizerState.ended:
collectionView.endInteractiveMovement()
default:
collectionView.cancelInteractiveMovement()
}
}
Hi all I am on a tutorial for maps but it is using Xcode 7 in the tutorial.
In the tutorial he uses this link but it has been stopped in the new version.
Can anybody let me know the best way to duplicate this?
I have added NSLocationWhenInUseUsageDescription in the plist.
func locationAuthStatus() {
if CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
map.showsUserLocation = true
}else {
//cant get this to work in ios10
locationManager.requestWhenInUseAuthorization()
}
}
Any help will be appreciated.
solved....
I realised that I had created a constant named locationManager but spelt it lacationManager instead, I couldn't work out why it was asking me to change it to LacationManager then I realised the spelling mistake.
all works fine now.