How to force resolve Swift Package in Xcode

Issue #784 Every time I switch git branches, SPM packages seem to be invalidated and Xcode does not fetch again, no matter how many times I reopen. Running xcodebuild -resolvePackageDependencies does fetch but Xcode does not recognize the resolved packages and still reports missing packages. The good thing is under menu File -> Swift Packages there are options to reset and resolve packages...

February 26, 2021 路 1 min 路 Khoa Pham

How to search using regular expression in Xcode

Issue #698 Xcode has powerful search. We can constrain search to be scoped in workspace, project or some folders. We can also constrain case sensitivity. Another cool thing that people tend to overlook is, besides searching based on text, we can search based on references, definitions, call hierarchy, and 馃帀 regular expressions. Searching for regular expression gives us extra power when it comes to limit our search based on some criteria....

November 17, 2020 路 2 min 路 Khoa Pham

How to declare commands in Xcode extensions

Issue #638 Use commandDefinitions in XCSourceEditorExtension. import Foundation import XcodeKit class SourceEditorExtension: NSObject, XCSourceEditorExtension { func extensionDidFinishLaunching() { } var commandDefinitions: [[XCSourceEditorCommandDefinitionKey: Any]] { func makeDef( _ className: String, _ commandName: String ) -> [XCSourceEditorCommandDefinitionKey: Any] { guard let bundleId = Bundle(for: type(of: self)).bundleIdentifier else { return [:] } return [ XCSourceEditorCommandDefinitionKey.identifierKey: bundleId + className, XCSourceEditorCommandDefinitionKey.classNameKey: className, XCSourceEditorCommandDefinitionKey.nameKey: commandName ] } return [ makeDef(TypeCommand.className(), "Type"), makeDef(ReloadCommand.className(), "Reload"), ] } } There is a weird crash that we can鈥檛 seem to declare functions or use commandDefinitions, the workaround is to declare in plist...

April 13, 2020 路 1 min 路 Khoa Pham

How to declare commands in Xcode extenstions

Issue #638 Use commandDefinitions in XCSourceEditorExtension. import Foundation import XcodeKit class SourceEditorExtension: NSObject, XCSourceEditorExtension { func extensionDidFinishLaunching() { } var commandDefinitions: [[XCSourceEditorCommandDefinitionKey: Any]] { func makeDef( _ className: String, _ commandName: String ) -> [XCSourceEditorCommandDefinitionKey: Any] { guard let bundleId = Bundle(for: type(of: self)).bundleIdentifier else { return [:] } return [ XCSourceEditorCommandDefinitionKey.identifierKey: bundleId + className, XCSourceEditorCommandDefinitionKey.classNameKey: className, XCSourceEditorCommandDefinitionKey.nameKey: commandName ] } return [ makeDef(TypeCommand.className(), "Type"), makeDef(ReloadCommand.className(), "Reload"), ] } } There is a weird crash that we can鈥檛 seem to declare functions or use commandDefinitions, the workaround is to declare in plist...

April 13, 2020 路 1 min 路 Khoa Pham

How to use application will terminate in macOS

Issue #601 On Xcode 11, applicationWillTerminate is not called because of default automatic termination on in Info.plist. Removing NSSupportsSuddenTermination to trigger will terminate notification func applicationWillTerminate(_ notification: Notification) { save() } <key>NSSupportsAutomaticTermination</key> <true/> <key>NSSupportsSuddenTermination</key> <true/> ...

February 12, 2020 路 1 min 路 Khoa Pham

Xcode tips

Issue #584 Read more https://dasdom.github.io/a-breakpoint-i-cannot-live-without/ ...

January 26, 2020 路 1 min 路 Khoa Pham

How to fix library not found with SPM and CocoaPods in Xcode

Issue #572 After migrating a few pods to use SPM, some libraries fail to load. This is because the workspace now uses both SPM and cocoapods code signature in 鈥 not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?) The workaround is to disable Library validation...

January 8, 2020 路 1 min 路 Khoa Pham

How to use test environment variables with shared scheme in Xcode

Issue #557 Use ProcessInfo to access environment variables. ProcessInfo().environment["username"] Duplicate main shared scheme TestApp to TestAppWithCredentials, but don鈥檛 share this TestAppWithCredentials scheme...

December 28, 2019 路 1 min 路 Khoa Pham

How to do localization in Xcode

Issue #545 Xcode 10 Localization catalog and XclocReader New Localization Workflows in Xcode 10 Xcode 11 localized screenshots Creating Great Localized Experiences with Xcode 11 ...

December 16, 2019 路 1 min 路 Khoa Pham

How to use xcodebuild

Issue #544 man xcodebuild man xcodebuild XCODEBUILD(1) BSD General Commands Manual XCODEBUILD(1) NAME xcodebuild -- build Xcode projects and workspaces SYNOPSIS xcodebuild [-project name.xcodeproj] [[-target targetname] ... | -alltargets] [-configuration configurationname] [-sdk [sdkfullpath | sdkname]] [action ...] [buildsetting=value ...] [-userdefault=value ...] xcodebuild [-project name.xcodeproj] -scheme schemename [[-destination destinationspecifier] ...] [-destination-timeout value] [-configuration configurationname] [-sdk [sdkfullpath | sdkname]] [action ...] [buildsetting=value ...] [-userdefault=value ...] xcodebuild -workspace name.xcworkspace -scheme schemename [[-destination destinationspecifier] ....

December 15, 2019 路 40 min 路 Khoa Pham

How to use Derived data in Xcode

Issue #543 Workspace Workspace has its own DerivedData folder DerivedData ModuleCache.noindex workspace_name Build Products Debug-iphonesimulator Cat Dog Dog2 Index Info.plist Logs Build Debug Install Issues Package Test LogStoreManifest.plist Test-scheme_name-2019.12.15_21-08-32-+0100.xcresult scm.plist SourcePackages TextIndex Note that workspace always needs a scheme to work xcodebuild: error: If you specify a workspace then you must also specify a scheme. Use -list to see the schemes in this workspace. Project Project has its own DerivedData folder....

December 15, 2019 路 1 min 路 Khoa Pham

How to use test scheme in Xcode

Issue #541 Scheme action A scheme, either for app or test, consists of actions Run Used when Cmd+R. The executable specifies which app target to run Test Used when Cmd+U. The tests specifies which test target to run Test target recognises app targets via Test application and target dependency When specify test scheme, we are specifying Test action in test scheme, which builds test target, and by dependency, builds app target, then run test action in test scheme, which is the UITest...

December 14, 2019 路 1 min 路 Khoa Pham

How to set language and locale with xcodebuild

Issue #540 testLanguage and testRegion -testLanguage language Specifies ISO 639-1 language during testing. This overrides the setting for the test action of a scheme in a workspace. -testRegion region Specifies ISO 3166-1 region during testing. This overrides the setting for the test action of a scheme in a workspace. xcodebuild -project 'TestApp.xcodeproj' -scheme 'TestAppUITests' -configuration Debug -sdk iphonesimulator -UseModernBuildSystem=YES -destination 'OS=13.2.2,name=iPhone 11,platform=iOS Simulator' -testLanguage ja -testRegion ja_JP test ...

December 12, 2019 路 1 min 路 Khoa Pham

How to take screenshots for UITest in Xcodee

Issue #539 XCUIScreenshot extension XCTestCase { func takeScreenshot(name: String) { let screenshot = XCUIScreen.main.screenshot() let attach = XCTAttachment(screenshot: screenshot) attach.lifetime = .keepAlways add(attach) } } Gather screenshot for localization Creating Great Localized Experiences with Xcode 11 xcresult from Xcode 11 https://www.chargepoint.com/engineering/xcparse/ xcparse Command line tool & Swift framework for parsing Xcode 11+ xcresult xcresulttool Testing in Xcode Test plan WWDC19: Getting Started with Test Plan for XCTest ...

December 12, 2019 路 1 min 路 Khoa Pham

How to use Xcode

Issue #499 Build setting Build Library For Distribution Binary Frameworks in Swift It turns on all the features that are necessary to build your library in such a way that it can be distributed What does this error actually mean? Well, when the Swift compiler goes to import a module, it looks for a file called the Compiled Module for that library. If it finds one of these files, it reads off the manifest of public APIs that you can call into, and lets you use them....

November 12, 2019 路 2 min 路 Khoa Pham

Links for Xcode

Issue #499 Build setting Build Library For Distribution Binary Frameworks in Swift It turns on all the features that are necessary to build your library in such a way that it can be distributed What does this error actually mean? Well, when the Swift compiler goes to import a module, it looks for a file called the Compiled Module for that library. If it finds one of these files, it reads off the manifest of public APIs that you can call into, and lets you use them....

November 12, 2019 路 2 min 路 Khoa Pham

How to configure test target in Xcode

Issue #478 This applies to Main targets App Framework Test targets Unit tests UI tests Examples Dependencies used Main target: Sugar Test target: Nimble, Quick Examples Cocoapods Carthage Notes Make sure test target can link to all the frameworks it needs. This includes frameworks that Test targets use, and possibly frameworks that Main target uses ! Remember to 鈥淐lean Build Folder鈥 and 鈥淐lear Derived Data鈥 so that you鈥檙e sure it works....

October 29, 2019 路 2 min 路 Khoa Pham

How to use Apple certificate in Xcode 11

Issue #458 For push notification, we can now use just Production Certificate for 2 environments (production and sandbox) instead of Development and Production certificates. Now for code signing, with Xcode 11 https://developer.apple.com/documentation/xcode_release_notes/xcode_11_release_notes we can just use Apple Development and Apple Distribution certificate for multiple platforms Signing and capabilities settings are now combined within a new Signing & Capabilities tab in the Project Editor. The new tab enables using different app capabilities across multiple build configurations....

October 11, 2019 路 1 min 路 Khoa Pham

How to run app on beta iOS devices

Issue #343 Xcode 10.3 with iOS 13 sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport Xcode 10.3 with iOS 13.1 beta 2 sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.0/ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.1 Use DeviceSupport Download and unzip Device support https://github.com/iGhibli/iOS-DeviceSupport /Applications/Xcode/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport ...

August 1, 2019 路 1 min 路 Khoa Pham

How to convert your Xcode plugins to Xcode extensions

Issue #267 Original post https://medium.freecodecamp.org/how-to-convert-your-xcode-plugins-to-xcode-extensions-ac90f32ae0e3 Xcode is an indispensable IDE for iOS and macOS developers. From the early days, the ability to build and install custom plugins had given us a huge boost in productivity. It was not long before Apple introduced Xcode extension due to privacy concerns. I have built a few Xcode plugins and extensions like XcodeWay, XcodeColorSense, XcodeColorSense2, and Xmas. It was a rewarding experience. I learned a lot, and the productivity I gained was considerable....

May 23, 2019 路 20 min 路 Khoa Pham