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 · 8363 words · Khoa

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 · 111 words · Khoa

How to not use protocol extension in Swift

Issue #542 With protocol extension See code Puma Build is UsesXcodeBuild is UsesCommandLine /// Any task that uses command line public protocol UsesCommandLine: AnyObject {} public extension UsesCommandLine { func runBash( workflow: Workflow, program: String, arguments: [String], processHandler: ProcessHandler = DefaultProcessHandler() ) throws { // Code } func runProcess( _ process: Process, workflow: Workflow, processHandler: ProcessHandler = DefaultProcessHandler() ) throws { // Code } } /// Any task that uses xcodebuild public protocol UsesXcodeBuild: UsesCommandLine { var xcodebuild: Xcodebuild { get set } } public extension UsesXcodeBuild { func runXcodeBuild(workflow: Workflow) throws { try runBash( workflow: workflow, program: "xcodebuild", arguments: xcodebuild....

December 15, 2019 · 1 min · 161 words · Khoa

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 · 111 words · Khoa

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 · 68 words · Khoa

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 · 67 words · Khoa

How to fix UIToolbar Auto Layout issues

Issue #538 Hierarchy UIToolbar -> _UIToolbarContentView -> _UIButtonBarStackVie UIToolbarContentView _UIToolbarContentView's width should equal 0 _UIToolbarContentView's height should equal 0 Workaround that fixes 1 warning toolbar.setItems(items, animated: false) toolbar.updateConstraintsIfNeeded() Set frame explicitly Use a non .zero frame that is close to the view bounds width let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 375, height: 30)) DispatchQueue.main.async { self.toolbar.updateConstraintsIfNeeded() }

December 11, 2019 · 1 min · 60 words · Khoa

How to use passed launch arguments in UITests

Issue #537 Specify launch arguments In xcodebuild, specify launch arguments. You can specify this under Launch Arguments in Run action of the app scheme or UITest scheme -AppleLanguages (jp) -AppleLocale (jp_JP) (lldb) po ProcessInfo().arguments ▿ 11 elements - 0 : "/Users/khoa/Library/Developer/CoreSimulator/Devices/561F2B45-26B2-4897-98C4-8A917AEB48D2/data/Containers/Bundle/Application/436E0A43-8323-4F53-BBE0-6F75F674916F/TestAppUITests-Runner.app/TestAppUITests-Runner" - 1 : "-AppleLanguages" - 2 : "(ja)" - 3 : "-AppleTextDirection" - 4 : "NO" - 5 : "-AppleLocale" - 6 : "ja_JP" - 7 : "-NSTreatUnknownArgumentsAsOpen" - 8 : "NO" - 9 : "-ApplePersistenceIgnoreState" - 10 : "YES" In UITests, pass launch arguments from UITest scheme to UITest application...

December 10, 2019 · 1 min · 100 words · Khoa

How to add padding to left right view in UITextField

Issue #536 extension UITextField { func setLeftView(_ view: UIView, padding: CGFloat) { view.translatesAutoresizingMaskIntoConstraints = true let outerView = UIView() outerView.translatesAutoresizingMaskIntoConstraints = false outerView.addSubview(view) outerView.frame = CGRect( origin: .zero, size: CGSize( width: view.frame.size.width + padding, height: view.frame.size.height + padding ) ) view.center = CGPoint( x: outerView.bounds.size.width / 2, y: outerView.bounds.size.height / 2 ) leftView = outerView } }

December 10, 2019 · 1 min · 57 words · Khoa

How to set date color in UIDatePicker in iOS 13

Issue #535 datePicker.setValue(UIColor.green, forKey: "textColor") datePicker.setValue(false, forKey: "highlightsToday") In iOS 14 if #available(iOS 14.0, *) { datePicker.preferredDatePickerStyle = .wheels datePicker.tintColor = UIColor.green } Inspect attributes https://developer.apple.com/documentation/objectivec/nsobject/1415656-attributekeys

December 10, 2019 · 1 min · 26 words · Khoa

How to use bundle with rbenv

Issue #534 Workaround /Users/khoa/.rbenv/shims/bundler install

December 10, 2019 · 1 min · 5 words · Khoa

How to show localized text in SwiftUI

Issue #533 struct ContentView: View { @Environment(\.locale) var locale: Locale var body: some View { VStack { Text(LocalizedStringKey("hello")) .font(.largeTitle) Text(flag(from: locale.regionCode!)) .font(.largeTitle) } } }

December 9, 2019 · 1 min · 25 words · Khoa

How to show flag emoji from country code in Swift

Issue #532 func flag(from country: String) -> String { let base : UInt32 = 127397 var s = "" for v in country.uppercased().unicodeScalars { s.unicodeScalars.append(UnicodeScalar(base + v.value)!) } return s } Read moree Swift turn a country code into a emoji flag via unicode https://github.com/onmyway133/Smile

December 9, 2019 · 1 min · 45 words · Khoa

How to work with git

Issue #531 Expand commits in Sublime Merge { "expand_merge_commits_by_default": true, "translate_tabs_to_spaces": true } local hooks .git/hooks vs hooksPath git config core.hooksPath ~/.git-templates/hooks Only hooksPath gets run. Removing hooksPath make local hooks work https://stackoverflow.com/questions/39332407/git-hooks-applying-git-config-core-hookspath Use git templates https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook Define alias in zshrc vim ~/.zshrc alias check="~/.git-templates/hooks/check.sh" source ~/.zshrc pre-commit https://itnext.io/using-git-hooks-to-enforce-branch-naming-policy-ffd81fa01e5e (feature|fix|refactor)\/[a-z0-9-]+$

December 9, 2019 · 1 min · 50 words · Khoa

How to fix cropped image in UIImageView

Issue #530 Although UIImageView frame is correct, image is still cropped. Watch out for any layer.mask within view

December 6, 2019 · 1 min · 18 words · Khoa

How to use decoration view in UICollectionView

Issue #529 indexPath https://developer.apple.com/documentation/uikit/uicollectionviewlayoutattributes/1617786-layoutattributesfordecorationvie It is up to you to decide how to use the indexPath parameter to identify a given decoration view. Typically, you use the decorationViewKind parameter to identify the type of the decoration view and the indexPath information to distinguish between different instances of that view. Posts Add separator https://gist.github.com/tomaskraina/1eb291e4717f14ad6e0f8e60ffe9b7d3

December 5, 2019 · 1 min · 53 words · Khoa

How to do lense in Swift

Issue #528 What is lense https://www.schoolofhaskell.com/school/to-infinity-and-beyond/pick-of-the-week/a-little-lens-starter-tutorial A lens is a first-class reference to a subpart of some data type. For instance, we have _1 which is the lens that “focuses on” the first element of a pair. Given a lens there are essentially three things you might want to do View the subpart Modify the whole by changing the subpart Combine this lens with another lens to look even deeper...

December 4, 2019 · 1 min · 205 words · Khoa

How to convert from callback to Future Publisher in Combine

Issue #527 import Foundation import Combine public typealias TaskCompletion = (Result<(), Error>) -> Void public protocol Task: AnyObject { var name: String { get } func run(workflow: Workflow, completion: TaskCompletion) } public extension Task { func asPublisher(workflow: Workflow) -> AnyPublisher<(), Error> { return Future({ completion in self.run(workflow: workflow, completion: completion) }).eraseToAnyPublisher() } } let sequence = Publishers.Sequence<[AnyPublisher<(), Error>], Error>( sequence: tasks.map({ $0.asPublisher(workflow: self) }) )

December 2, 2019 · 1 min · 65 words · Khoa

How to make init with closure in Swift

Issue #526 public class Build: UsesXcodeBuild { public var arguments = [String]() public init(_ closure: (Build) -> Void = { _ in }) { closure(self) } } Use function builder public class Workflow { public var workingDirectory: String = "." public let tasks: [Task] public init(@TaskBuilder builder: () -> [Task]) { self.tasks = builder() self.tasks.forEach { task in task.workflow = self } } public init(@TaskBuilder builder: () -> Task) { self....

December 1, 2019 · 1 min · 113 words · Khoa

How to test a developing package with Swift Package Manager

Issue #525 Use macOS Command Line project Example Puma Create a new macOS project, select Command Line Tool Drag Puma.xcodeproj as a sub project of our test project Go to our TestPuma target, under Link Binary with Libraries, select Puma framework Puma has dependencies on PumaCore and PumaiOS, but in Xcode we only need to select Puma framework In code, we need to explicitly import PumaiOS framework if we use any of its classes...

November 30, 2019 · 2 min · 245 words · Khoa