Xcode compile fails on internal error - ios

I am having issues compiling a previously working xcode project. All it says is that there is an internal error. I have tried cleaning the project and the build files. The error is listed below. Any idea of how to fix this? I have tried both xcode 7.2 and 7.2.1.
Base.lproj/Main.storyboard: error: Internal error. Please file a bug at bugreport.apple.com and attach "/var/folders/tc/_8l_rs9n055_0zqdny0k89nr0000gp/T/IB-agent-diagnostics_2016-03-01_09-46-22_280000".
The error it shows I am getting is below. How do I find what view it is referring to?
Exception name: NSInvalidArgumentException
Exception reason: Unable to parse constraint format:
Unable to interpret '|' character, because the related view doesn't have a superview
H:|[self]

My guess is that you are using visual constraint language to constrain views.
The error says
Unable to parse constraint format: Unable to interpret '|' character, because the related view doesn't have a superview H:|[self]
which means that you are applying those constraints before you have actually added the view to its superview (the constraint tries to refer to the superview edge (the pipe | symbol)) which is not present because the view you are trying to apply constraints to has not yet been added to its superview.
So here is a scenario that could cause the issue:
let view = UIView()
let subview = UIView()
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("|[v]|"))
And how to solve it:
let view = UIView()
let subview = UIView()
view.addSubview(subview) // you have to add it to the superview before applying constraints
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("|[v]|"))

Related

SnapKit Updating Constraint causes conflict

I'm building an iOS app against iOS 12 SDK, Swift 4 and SnapKit 4.2
I want to update a constraint when I tap a button but it creates a conflict with the previous version of the constraint.
Here's my code:
private var menuConstraint: Constraint?
override func updateViewConstraints() {
super.updateViewConstraints()
menuVc.view.snp.makeConstraints { (make) in
self.menuConstraint = make.top.equalTo(view.snp.top).constraint
make.right.equalTo(view.snp.right)
make.width.equalTo(100)
make.height.equalTo(100)
}
}
#objc func onMenuTap() {
self.menuConstraint!.update(offset: 100)
}
When onMenuTap is called I get the following error:
[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.
(
"<SnapKit.LayoutConstraint:0xABC#MyViewController.swift#77 UIView:0xDEF.top == UIView:0xGHI.top>",
"<SnapKit.LayoutConstraint:0xABC#MyViewController.swift#77 UIView:0xDEF.top == UIView:0xGHI.top + 100.0>"
)
As you can see the previous version of the top constraint (without the offset) is conflicting with the new version. It's as if it didn't update the existing constraint but instead just created a new one.
I've tried a few variations:
wrapping the update line in a snp.updateConstraints closure
setting an initial offset when first creating the constraint
grabbing the underlying LayoutConstraint and updating constant directly.
I always get the same error message.
Do I have something configured wrong?
Don't put constraints inside updateViewConstraints as it'll recreate constraints as it's called multiple times so set the code inside viewDidLoad

#IBDesignable - view not rendering as expected

I have a custom UIView subclass that I am trying to render using #IBDesignable.
I have an#IBInspectable property named image, which I set from the interface builder.
When I open the interface builder the image that I choose is not rendered properly in the view, that is, it looks like some trouble with autolayout.
When I checked the Report navigator I am getting a warning in the Interface Builder group.
Showing All Messages
(null): -pie being ignored. It is only used when linking a main executable
This happens under the Link <IBDESIGNABLE_EXECUTABLE> section.
I have no idea how to fix this. Tried many solutions from SO. Cleaning build folder, clearing derived data etc. Nothing worked.
Please provide your valuable comments or a solution to this problem. Thanks! :)
EDIT:
Thanks to #Rob I could zero in to the problem.
What I have:
An IBDesignable UIView Subclass with properties:
an#IBInspectable property named image.
an ImageView
a ScrollView
I initialise and add the ScrollView and ImageViews as subviews using
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialiseImageView()
}
override init(frame: CGRect) {
super.init(frame: frame)
initialiseImageView()
}
Problem:
In initialiseImageView():
I add the scrollView as subview of the UIView and ImageView as the subview of the scrollView to use the viewForZooming delegate. I also add constraints to keep the views in place.
The problem is when I use:
self.translatesAutoresizingMaskIntoConstraints = false
If I use this I get autolayout warnings at runtime. But the imageView is misplaced in interface builder, although the image is rendered correctly.
If I comment the same, everything is as expected in interface builder. But the UI breaks at runtime due to AutoresizingMaskIntoConstraints.
I have the code in github. I am trying the latter approach mentioned in TN2154
I am setting all AutoresizingMaskIntoConstraints to be false and adding the constraints for the subviews in the code itself. The constraints for the UIView subclass are added in the interface builder directly and no warnings exist as of now. The code works as expected at runtime also. The IBDesignable part is the one that is not working as expected.
Strangely enough, When I removed the line
self.translatesAutoresizingMaskIntoConstraints = false
everything is working perfectly. The error that I used to get at runtime is now gone. I don't know if something else that I did fixed it. Thanks a lot for helping to pin point the issue #Rob.
BTW, I just did a quick #IBDesignable with an #IBInspectable that was a UIImage and a draw(rect:) that rendered that image and it worked fine:
#IBDesignable class CustomView: UIView {
#IBInspectable var image: UIImage?
override func draw(_ rect: CGRect) {
image?.draw(at: CGPoint.zero)
}
}
When I do that in a separate target (as one should with designables), I also see the same warning:
ld: warning: -pie being ignored. It is only used when linking a main executable
I suspect that warning may be a red herring. The man pages for ld described -pie option as follows:
This makes a special kind of main executable that is position independent (PIE).
You can toggle this setting if you go to the link settings for your designables' target and change the "Generate Position-Dependent Executable" in the "Linking" settings. Then that warning will go away. Personally, I've never noticed that warning and never changed this settings, and never noticed any adverse affects, but if you want to confirm this for your own sense of satisfaction, try changing this setting and see if you can get the warning to go away.
Bottom line, your #IBDesignable problem probably rests elsewhere, but it's hard to diagnose on the basis of the information provided. We need more information (or, ideally, a MCVE).
It's hard to comment on your autolayout warnings without seeing what those warning are, but I'd guess that (a) you're adding a subview; but (b) not setting the constraints for said subview; and therefore (c) that when you set translatesAutoresizingMaskIntoConstraints = false, that your constraints are ambiguous and therefore result in error messages and unexpected layout at runtime. Or maybe it's a symptom of the idiosyncrasies of scroll views. But it's hard to say without seeing (a) actual autolayout error; (b) what subviews your #IBDesignable added; and (c) what constraints you added for your subviews.
Bottom line, make sure that your programmatically added subviews have all of their constraints unambiguously defined. Also remember that constraints for scrollview subviews act differently that many constraints, defining the contentSize of the scroll view rather than the size of the subviews. (On this latter point, see TN2154.)
For me, I deleted some no longer existing ibdesignable variables.
They were stuck in the User defined runtime attributes.
Deleting that, and then cleaning build folder, rebuilding resolved this for me!

UIViewController hangs in Xcode 7

Not sure whether title is correct or not, I'm calling newViewController on button click but it is not rendering that. as it was working fine in Xcode 6.4 but in Xcode 7 its hangs the UI and not showing new view controller after pushViewController.
this is the error logs which print on console
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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x16bbe0c0 V:[UIView:0x157fb230(45)]>",
"<NSLayoutConstraint:0x16bbc390 V:[UIView:0x157fb230(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x16bbe0c0 V:[UIView:0x157fb230(45)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
I add break point in viewDidLoad of next controller it is calling that but not loading that ViewController.
EDIT
I seen that CPU usage are at 100% and second thing that my Viewcontroller have tableView so when i debug then it call my CellForRowatIndexPath for all the rows, so not sure where it exactly getting freezed my ViewController.
UPDATE
I'm updating my question again, I removed that error constrains (i.e. 45 and 0) now I'm not getting any constrains warning or error on console but still my UIView is freezes. Please help Thanks
It seems like you have two conflicting height constraints in one of your views. One is telling your view to have 0 height, the other tells it to have 45.
Also not related to the error message: You do not need the "Align center X to Superview" constraint, as that will be implicit because of leading/trailing constraints.
EDIT:
Try the implementing the following initializer and instantiate it with [MyViewControllerClass new]. I have had trouble previously with the default behavior of the viewcontroller loading a nib with the same name as the view controller by default. This is of course assuming you're not using a storyboard, in which case I can't really help.
- (instancetype)init
{
self = [super initWithNibName:#"MyNibName" bundle:nil]
if (self)
{
}
return self
}
I had this problem as well and it had to do with placeholder text (I am using storyboard). Clear out any placeholder text you have in fields and see if it works! Mine does. If that helps, just set the placeholder text in code as opposed to storyboard. I answered a similar question here:
Instantiating Modal view controller freezes the app - Probable issue with Xcode 7

iOS & Xcode 6: Auto Layout Text Scaling on a Button

I have a Today Extension with a button and UIImage. The button and image scale and center themselves correctly except the button's text is not scaled. I am writing this extension in Swift. I have tried these so far:
myButton.titleLabel.adjustsFontSizeToFitWidth = true
myButton.adjustsFontSizeToFitWidth = true
Both return errors.
Without seeing more code or the specific errors, the only thing I can see is that titleLabel is an optional. As written, the compiler would show the error 'UILabel? does not have a member named 'adjustsFontSizeToFitWidth'. Writing the line as myButton.titleLabel?.adjustsFontSizeToFitWidth = true should fix the error.
Also, UIButton doesn't have a member named 'adjustFontSizeToFitWidth' so the second line would throw the same error as above.
Try fixing that error as indicated above and see if your AutoLayout issue works.

Could not instantiate class named IBNSLayoutConstraint

I'm using XCode6 beta and trying out Swift. When I put some auto layout constraints in a view controller the app crashes with the following error:
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named IBNSLayoutConstraint'
You're getting this error because you've set a constraint to an IBOutlet that is removed at runtime. This happens when you set the constraint to be a placeholder in Interface Builder. Since the constraint is removed, when it goes to unarchive it, it throws an error saying it can't do so.
There are two ways to correct this.
Method 1
Right-click on your Storyboard > Open As > Source Code
In the opened storyboard xml, search for placeholder="YES".
You'll find constraints that are set to be removed at runtime. Remove the placeholder attribute from the constraint, save and close.
Run the app and your problem should be fixed.
Method 2
Find the constraint that's causing your problems in Interface Builder. Uncheck the Placeholder option in the GUI. This should be one of the constraints that's set to an IBOutlet in the ViewController that's causing your crash.
This is what it should look like:
Alternative
Assuming you actually want the constraint to be a placeholder, then you'll need to remove any referencing outlets. To do this, select the constraint that you wish to be a placeholder. Then open the connections inspector (the button furthest to the right that looks like this: (->) ) and then remove any referencing outlets that may exist on that constraint.
I had the same problem just now and the following worked for me.
I released a working version of my app to the App Store, came back to work on it again a few days later tapping onto one my tabs in the UITabBarController it crashed with the error:
Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named IBNSLayoutConstraint'
I didn't have any placeholder layout constraints that I was aware of or constraint outlets that shouldn't have been defined.
The solution for me was to simply turn size classes off and keep size class data for iPhone (App is only for iPhone). This must've deleted anything I'd missed in the size classes. I want size classes so I turned them back on and the app just worked again.
This might not be necessarily a constraint problem. For me it was caused by not having checked "Installed" for a size class that was applying to my layout, see here
There was some problem with using size classes. I disabled that option from the storyboard properties and use only auto layout. It wasn't such a big problem since the app is iPhone only.
What ended up happening to me was that I cut a subview inside of Interface Builder to copy it into another xib. This left the subview in original xib Interface builder with it being greyed out. After removing the subview from it's original place (by selecting and deleting). I was able to get rid of the error.
There is an option in the inspector window when you select the xib file that will not use the constrains under "Show file the inspector" in the inspector called "Use autolayout".
I made a change to a scroll view so that it would let the picker controls embedded in it work properly using a solution I found elsewhere in Stackoverflow.
My new storyboard simply added these attributes to the scroll view, which seemed fine to me.
delaysContentTouches="NO" canCancelContentTouches="NO"
But in addition, I saw in my storyboard in another scene the following new fragment:
<variation key="default">
<mask key="subviews">
<exclude reference="86H-aM-wei"/>
</mask>
</variation>
I have no idea where it came from. At first I ignored it because everything seemed to work find on my dev machine. But when the build was built as Release and tested, I got the crash. Removing that spurious(?) fragment fixed the crash and has not seemed to impact anything else.
I had this issue when I had a button in a custom UICollectionViewCell, and had some of its constraints as IBOutlets on that class. I moved the button from the cell to the parent view controller and the IBOutlets were still referenced in the cell but didn't actually exist on the cell so blew everything up. Just needed to remove those IBOutlets and everything worked fine again!

Resources