Clear derived data (located at
~/Library/Developer/Xcode/DerivedData
)
AND remove MyApp.xcodeproj/project.xcworkspace
After clearing derived data, the package dependencies in my Xcode
project tree are always red.
In Xcode, go to:
File > Packages > Reset Package Caches
credit: https://www.reddit.com/r/iOSProgramming/comments/wut32p/comment/ilcjsnq
See if it improves debugger times
https://stackoverflow.com/a/77926174/143447
Crash reports are now in Xcode Organizer at
Window > Organizer
cd ~/dev/my-proj
xed .
Add a SPM package to a sample project, while allowing the package to be edited:
Go to File > Add Package Dependencies
Press the “Add local” button at the button of the window
Choose the folder containing the package
Source: https://forums.swift.org/t/how-to-add-local-swift-package-as-dependency/26457/48
Package Dependencies
tabLong press the Play button, select Profile (or use cmd+i), select Time Profiler, tap the record button
It’s helpful to view intermediate images when debugging image transformation code.
Steps:
- Encounter a breakpoint in transformation code
- Tap the ‘Show variables view’ button in bottom right of debug
area
- Highlight the image variable
- Press spacebar
Returning to Apple work. Refresher:
Reveal file in project tree | cmd+shift+j |
Toggle project drawer | cmd+0 |
Toggle inspector drawer | cmd+opt+0 |
Toggle console and debug panel | cmd+shift+y |
Navigate between headings in project drawer | cmd+1 through
cmd+9 |
Go back | cmd+ctrl+left-arrow |
Go forward | cmd+ctrl+right-arrow |
Go to compilation errors | cmd+5 |
Browse symbols in currenct file | ctrl+6 |
Fuzzy file search | cmd+shift+o |
Show autocomplete suggestions | ctrl+space |
Run | cmd+r |
Stop | cmd+. |
Format code (indent, reindent, format) | ctrl+i |
Indent code | cmd+] |
Deindent code | cmd+[ |
Format single line into multi | ctrl+m |
Interface builder quick add | cmd+shift+l |
Interface builder toggle inspect panel | cmd+opt+0 |
Simulator switch to dark mode | cmd+shift+a |
Refresh SwiftUI preview | cmd+opt+p |
Multiple cursors (adjacent) | cmd+shift+down-arrow |
Multiple cursors (adjacent) | opt mouse-drag |
Multiple cursors (non-adjacent) | ctrl+shift mouse-click |
Edit scheme | cmd+shift+comma |
Show single editor pane | cmd+shift+ctrl+enter |
Create docstring (cursor on fn signature) | cmd+opt+/ |
Open ‘quick actions’ in editor | cmd+shift+a |
Set breakpoint | cmd+\ |
Go to line | cmd+l |
Edits to a fresh Xcode install:
Settings > Editing > Uncheck suggest completions while typing
> Uncheck use escape key to show completion suggestions
> Check 'Automatically trim trailing whitespace'
> Check 'Including whitespace-only lines'
Settings > Behaviors > Running > Generates Output > Uncheck 'Show debugger'
~/Library/Developer/CoreSimulator
~/Library/Developer/Xcode/iOS DeviceSupport
/Library/Developer/CoreSimulator/Profiles/Runtimes
Source: https://stackoverflow.com/a/57929678/143447
In shell:
xcrun simctl shutdown all && xcrun simctl erase all
File > Project Settings > Derived Data > Project-relative Location > Enter “Build”
Toggle preview: cmd+opt+enter
Refresh preview: cmd+opt+p
Show editor only: cmd+enter
Initial setup:
sudo xcode-select -switch /Applications/Xcode6-Beta5.app
Preferences > Text Editing:
Set:
Automatically trim trailing whitespace
Including whitespace-only lines
Unset:
Suggest completions while typing
Preferences > General:
Unset:
Show live issues
Preferences > Key Bindings:
Show completions: ctrl+n // (autocomplete, suggestions)
Edit > Format > Spelling and Grammar > Uncheck 'Check spelling while typing'
xcrun simctl spawn booted log config --subsystem com.apple.CoreTelephony --mode level:off
xcrun simctl spawn booted log config --subsystem com.apple.boringssl --mode level:off
xcrun simctl openurl booted "https://www.example.com/content?id=2"
simctl openurl myapp://
Right click on a view and “Print description”. Then use lldb with the address:
expr ((UILabel *)0x7f8ff9d102e0).text = @"Hi"
po ((UILabel *)0x7f8ff9d102e0).text
Or
(lldb) expr UILabel *$label = (id)0x7f8ff9d102e0
(lldb) po $label.text
After using expr to change a property of the view, I can use
CATransaction.flush()
instead of continuing within debugger
to see updates.
It’s possible to use swift too, but obj-c is better for this:
(lldb) expr let $label = unsafeBitCast(0x7f8ff9d102e0, to: UILabel.self)
Put this in ~/.lldbinit
command regex let s/(.+): (.+) = (0x[[:xdigit:]]+)/expr let $%1 = unsafeBitCast(%3, to: %2.self)/
Then
(lldb) let label: UILabel = 0x7f8ff9d102e0
(lldb) po $label
cmd+down_arrow
repeatedly
Put cursor in method signature, then opt+cmd+/
Turn this on to see how far along Xcode’s file indexer is:
defaults write com.apple.dt.Xcode IDEIndexerActivityShowNumericProgress -bool true
Turn this on to see the amount of time each build takes:
defaults write com.apple.dt.Xcode ShowBuildOperationDuration -bool YES
Add to “other swift flags” to debug long compilation times:
-Xfrontend -debug-time-function-bodies
-Xfrontend -warn-long-function-bodies=100
cmd+opt+click
cmd+ctrl+r
defaults write com.apple.dt.XCode “IDEIndexDisable” 1
Window > Devices and Simulators (or Cmd+Shift+2)
Tap on connected device.
:: Scroll up in main pane
Tap on the “View Device Logs” button
cmd+’
Keybindings > All > “show completion list” set to
ctrl+n
This is how I rename a full project in Xcode.
Check source into version control before attempting.
In this example, I’m renaming the Xcode project ‘RenameMe’ to
‘GreatProject’:
rename s/RenameMe/GreatProject/ ./*
rename s/RenameMe/GreatProject/ ./GreatProject/*
find * -type f | LC_CTYPE=C xargs -I {} sed -i '' 's/RenameMe/GreatProject/g' '{}'
View > Assistant Editor > Stack all views horizontally
Quit and restart workspace
Punch this into shell:
sudo /usr/libexec/xpccachectl --verbose
Disable Xcode’s management of version control. Manage it myself:
Xcode > Preferences > Source Control > Disable source control
nw_socket_set_common_sockopts
)Go to Edit Scheme > Run > Arguments > Environment Variables and add:
Name:OS_ACTIVITY_MODE value:disable
Tap and hold the play button in the bottom right corner of the editor
pane,
an option will display to manually run.
Next, bind the “Execute Playground” menu item to cmd+p, (this will
disable print, which I don’t need anyway)
Now run the playground with cmd+p
~/Library/MobileDevice/Provisioning Profiles
Or:
Xcode > Preferences > Accounts > View Details
cmd+'
or cmd+ctrl+'
Xcode normally refuses to shrink to half my screen’s width.
I use spectacle to snap windows to half the screen, but Xcode gives me
problems.
The trick is to turn off Xcode’s toolbar! Then it happily snaps to half
the screen:
Go to View > Hide Toolbar
If Xcode is showing declarations instead of full definitions,
go to Navigate > Jump to Original Source
cmd+shift+?
Then start typing for fuzzy search (for example, try ‘interface’)
Behaviors > Running > Generates Output, uncheck “show project navigator”
Edit scheme: cmd+shift+,
Open documentation: cmd+shift+0
Format code (indent, reindent, format): ctrl+i
Toggle project navigator: cmd+0
Stop build, stop running: cmd+.
Autocomplete: ctrl+n
(I change this from the default of
ctrl+space
)
Hide issues and message bubbles: cmd+ctrl+m
(this stopped
working at some point)
Run app on simulator:
xcodebuild -configuration Debug -sdk iphonesimulator -workspace <workspace-name>.xcworkspace -scheme <scheme-name> -destination platform='iOS Simulator',OS=7.0.3,name='iPhone 5s'
List schemes:
xcodebuild -configuration Debug -sdk iphonesimulator -workspace Turtle4.xcworkspace -list
Modify the location at
Xcode > Preferences > Locations > Command Line Tools
Toggle between editor and assistant with cmd+enter
and
cmd+opt+enter
To get a device with a more recent SDK on it than is compatible with current Xcode version, get the latest Xcode dmg and copy these directories:
/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs$ sudo cp -Rf iPhoneSimulator5.1.sdk /Xcode4/Platforms/iPhoneSimulator.platform/Developer/SDKs/
/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs$ sudo cp -Rf iPhoneOS5.1.sdk /Xcode4/Platforms/iPhoneOS.platform/Developer/SDKs/
/Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport$ sudo cp -vRf 5.1\ \(9B176\) /Xcode4/Platforms/iPhoneOS.platform/DeviceSupport/
Source: http://stackoverflow.com/questions/9649313/is-there-a-way-to-downgrade-from-ios-5-1-to-ios-5-0
Copy an existing template to start.
Mac templates are here:
/Developer/Library/Xcode/Project Templates/Application
iPhone templates are here:
/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project
Templates/Library
Create my own template at:
~/Library/Application Support/Developer/Shared/Xcode/Project
Templates/
Punch cmd+8
and then tap the little plus sign at the
bottom, and tap “add symbolic breakpoint”:
symbol: objc_exception_throw
Module: libobjc.A.dylib
Then right click it and select
Move Breakpoint To > User
When the breakpoint hits, to get the exception message type
po $eax
Sources:
http://jf.omnis.ch/archives/2011/04/efficient-exception-debugging-with-xcode-4.html
http://developer.apple.com/library/mac/#technotes/tn2124/_index.html
Use the /bin/csh
shell to replicate commands from the
“Build Results” phase.
Go to the XCode 4 breakpoint navigator.
Click the + button and choose “Add Symbolic Breakpoint”
Set Symbol to:
"-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]"
Click “Done”
From: http://stackoverflow.com/questions/6007938/how-to-make-xcode4-stop-at-nsassert-failure
Switch between header files and source with cmd+ctrl+up
and cmd+ctrl+down
Navigate back and forwards with cmd+ctrl+left
and
cmd+ctrl+right
Switching between versions of Xcode:
~$ sudo xcode-select -switch <location-of-xcode1>
~$ sudo xcode-select -switch <location-of-xcode2>
iOS SDKs are now in ~/Developer/iPhone*/SDKs
To weak link a framework:
Or add -weak_freamwork UIKit
to Other Linker Flags
Start brackets on the next line for autocomplete, also remove space after if,else,etc and parenthesis:
defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict PreExpressionsSpacing "" BlockSeparator "\n"
From: http://stackoverflow.com/questions/392749/xcode-adjusting-indentation-of-auto-generated-braces
To get ‘home’ and ‘end’ keys to move to beginning of line / end
of line, go to Xcode > Preferences > Key Bindings.
Duplicate xcode default settings and name it ‘lz’.
Then change “Move to end of line” and “Move to beginning of line” by
double clicking on them.
Modify “Move to beginning (and end) of line extending selection” to use Shift+Home / Shift+End
Modify “Page up” and “Page down” to use the page up and page down keys (for some reason they are set to default as scroll up/down
Go to Run > Debugger Display > Disassembly Only, then use “step
into” just like normal.
For instance, put a breakpoint right at NSApplicationMain and start
stepping through assembly to see what it does.
Turn off warn before undo:
defaults write com.apple.Xcode XCShowUndoPastSaveWarning NO
Source: http://borkware.com/quickies/one?topic=xcode
Hide project tree and file list:
cmd+opt+shift+e
Hide file list:
cmd+shift+e
Hold opt and click the tiny box in the upper right under the lock icon.
opt+double click
on a symbol
Rearranging stuff in xcode to match the filesystem is a pain,
I have found this works to move all images to their own directory:
Delete all images in the Resources group and select Move to
Trash
Restore everything but the project file:
git status | awk '{if ($2 == "deleted:") {print $3}}' | xargs git checkout
Create a new directory on the file system called Images
Move all png files to the images directory
Drag the images directory into Xcode under the Resources group (recursively create groups must be checked)
shift+opt+cmd L/R arrow
Select the folder to sort, click on Edit > Sort > By Name
Do not drag and drop any file from any “group” into another group, it won’t move on the filesystem and you are left with a project drawer that doesn’t reflect your file structure.
Instead, delete any groups you are about to change in xcode, make the
changes on the file system, then go to
Add > Existing File
and make sure “recursively create
groups” is selected.