Xcode9 crashes when adding multiple bar button items to toolbar

Version:


Xcode 9a235


When I drag a toolbar into my view, and then try to add multiple bar button items into the toolbar, if I change one of the bar button items from System Item to "Reply", "Action" or any of those icons, the page hangs forever and I get stuck at a spinning wheel.


Please help!

Replies

Was using current version. I'm upgrading to xcode 9.1 as I type this. I'll let you know what happens.

same problem here..soo annoying....

Have you solved the problem? I am now having the same problem.

Same problem here. Ugh!

Same problem. Setting "View as" to iPhone SE also freezes Xcode 9.1. Xcode has amazing features, but has been consistently unreliable since Swift. I wonder if Xcode is tested at Apple before release.

Annoying that our apps must go through a review process but Apple will happily push out their own buggy software!


I threw together this hacky script that will transform all the button bar items in a storyboard to change the icons to 'cancel'. It records the original button bar items to a file you provide. This means you can now edit the storyboard file in the ui. Except all the button bar items will be cancel icons. To restore these run the script again and the original button bar icons will be restored.


We keep all our storyboard items in one huge storyboard file so this script was not created with multiple storyboards in mind! Use at own risk 😀



import os
import termcolor


# your storyboard file here!
currentStoryboardFilename = YOUR ORIGINAL STORYBOARD FILE HERE


originalStoryboardWithMetadataFileName = A FILE NAME FOR STORING THE ORIGINAL BUTTON BAR ITEMS


# temp file that gets deleted after script is run
transformedStoryboardFileName = "transformedStoryboard" 


barButtonItem = "barButtonItem"
systemItem = "systemItem"
systemItemWithEqualsAndQuote = systemItem + "=\""
requiredItems = [barButtonItem, systemItem]


cancel = "cancel"
flexibleSpace = "flexibleSpace"
fixedSpace = "fixedSpace"
systemItemIsCancel = "systemItem=\"cancel\""
idString = "id=\""
skipItems = [flexibleSpace, fixedSpace, systemItemIsCancel]


metadataHeader = "###metadata#"


def getOriginalBarButtons(storyboardWithMetadata):
isInMetadataSection = False
idList = []
# get list of (id, original line) tuples
for line in storyboardWithMetadata:
if isInMetadataSection:
idIndex = line.find(idString) + len(idString)
endQuoteIndex = line.find("\"", idIndex)
idValue = line[idIndex:endQuoteIndex]
idList.append((idValue, line))
if metadataHeader in line:
isInMetadataSection = True
return idList


def isLineABarButtonItem(line):
return all(item in line for item in requiredItems)


def isLineABarButtonToSkip(line):
return any(item in line for item in skipItems)


def getOriginalBarButtonItem(line, idList):
for idTuple in idList:
if idTuple[0] in line:
return idTuple[1]
# else
return line


def transformBarButtonToCancelIcon(line):
indexOfSystemItemValue = line.find(systemItemWithEqualsAndQuote)
indexOfSystemItemValue += len(systemItemWithEqualsAndQuote)
indexOfLastQuoteAroundSystemItemValue = line.find("\"", indexOfSystemItemValue)
firstPart = line[:indexOfSystemItemValue]
secondPart = line[indexOfLastQuoteAroundSystemItemValue:]


return firstPart + cancel + secondPart




def makeStoryboardSourceOnlyEditable():
currentStoryboardFile = open(currentStoryboardFilename, 'r')
originalStoryboardWithMetadata = open(originalStoryboardWithMetadataFileName, 'r')
transformedFile = open(transformedStoryboardFileName, 'w')

idList = getOriginalBarButtons(originalStoryboardWithMetadata)

for line in currentStoryboardFile:
if isLineABarButtonItem(line):
line = getOriginalBarButtonItem(line, idList)
transformedFile.write(line)


originalStoryboardWithMetadata.close()
currentStoryboardFile.close()
transformedFile.close()


os.remove(originalStoryboardWithMetadataFileName)
os.rename(transformedStoryboardFileName, currentStoryboardFilename)
termcolor.cprint("Transformed storyboard to source editing only mode", "green")



def makeStoryboardUIEditable():
# we don't have a copy of the original storyboard file so make a copy
originalStoryboardWithMetadata = open(originalStoryboardWithMetadataFileName, 'w')
currentStoryboardFile = open(currentStoryboardFilename, 'r')
transformedStoryboard = open(transformedStoryboardFileName, 'w')


originalItemsFooter = metadataHeader + "\n"
for line in currentStoryboardFile:
originalStoryboardWithMetadata.write(line)


# if line is a bar button item and has a systemItem then record original line at the top of the file as a comment
if isLineABarButtonItem(line) and not isLineABarButtonToSkip(line):
safeToOpenUILine = transformBarButtonToCancelIcon(line)
transformedStoryboard.write(safeToOpenUILine)
originalItemsFooter += "%s" % line
else:
transformedStoryboard.write(line)


originalStoryboardWithMetadata.write(originalItemsFooter)
originalStoryboardWithMetadata.close()
currentStoryboardFile.close()
transformedStoryboard.close()


os.rename(transformedStoryboardFileName, currentStoryboardFilename)
termcolor.cprint("Transformed storyboard to ui safe mode", "green")


if os.path.isfile(originalStoryboardWithMetadataFileName):
makeStoryboardSourceOnlyEditable()
else:
makeStoryboardUIEditable()

Same thing happens to me ! Simply cannot change the System Item of a Bar Button Item, placed in a ToolBar at the button, from Custom to <something else> when there is another Bar Button Item in the same ToolBar. Either I am not allowed to do this or this is a bug

I found a fix guys!!!! But I don't know how to explain it

Can you tell the fix? The Bug allready exists and i can not found any solution. 😟

xCode 9.2 Beta seems to fix this problem for me running OS X Sierra.

So I ran into this problem.
looked around the web to try to find a fix.

the fix fore me ended up beeing.

just change the layout to a different one.

I had it sett to iPhone 8 . changed it to iphone se and it worked. changed it back, it hanged.

I was having the same problem, every time I changed the toolbar icons to images Xcode would hang and I had to force quit.


The solution I found was simply to go to File -> Project Settings -> Build System: Change to New Build System.


After that I was able to change the toolbar icons without problems.

Ran across this problem in a "the-complete-ios11-developer-course " project. The video clearly showed the instructor adding the Bar-Button items to the Toolbar without a problem. I noticed my project was build for the iphone 8 whereas the instructor was building for iphone 7. Changed my scheme to ios 7 and that solved the problem!! It is surprising how much hocus pocus works in this day and age, but I am not about to try and figure out the rational explanation right now.

I literally have the same problem with Xcode older beta version and I just recently update Xcode to newest version Xcode 10 beta 3 hopefully this resolves the problem.