Posts

Post not yet marked as solved
3 Replies
1.1k Views
I am testing an app with in-app-purchases via TestFlight. Recently, when I try to test buying an in-app-purchase, a prompt "Apple Media Services Terms and Conditions have changed” started to appear which is always followed by an error “no connection” (internet connection is working fine). How can one resolve this situation and get back to a working setup for testing in-app-purchases? I already tried this to no avail: different internet connection/type restarting the device, using another device signing out of iCloud and back in again
Posted Last updated
.
Post not yet marked as solved
1 Replies
9.1k Views
)Hi,I noticed that when you declare a view property as @State and add a didSet block to it, it will have no effect: @State var someStateValue : Int = 0 { didSet { print(someStateValue) // <-- never called } }Makes sense because the property itself will be the State property wrapper and not the value.But still, it would be nice to have a way to add code to such a property being changed.Is there any way to react on a change of a @State property without making it @Published/using a ObservableObject?(same question was asked here: https://stackoverflow.com/questions/56550713/how-can-i-run-an-action-when-a-state-changes )Greetings,Ralf
Posted Last updated
.
Post not yet marked as solved
6 Replies
1.5k Views
I just had a great time in the 'Testing and Continuous Integration lab' trying to put in a voice for proper support for unit testing View code in XCTest. I'd like to share the FB ticket with my suggestion / wishes on that topic. Its based on what I learned from my iOS projects in the last years where I made an effort to properly do automated testing of View code. Would love to have a chat about the topic :) FB7760343: Supporting Unit Tests for View code (esp. SwiftUI) I'd like to be able to unit test View code (especially SwiftUI Views). Compared to UI tests, where you test all the app built together in a system black box test; I'd like to put a single View in the spotlight, configure it for a specific case programatially (like plugging in a stubbed communication service that returns an error) and assert that it does the right thing in this situation. The goal is to be able to test hundreds of cases very quickly / in mere seconds instead of having to wait minutes/hours to run a complex UI scenario. So you can re-run your unit tests after a little change and have a confident feedback in mere seconds that your code still works as expected. Including the parts of the code that are purely visual. Here is a simplified example project to show what I'd like to be able to do in a very simplified fashion: https://github.com/ralfebert/ExampleAppSwiftUIViewTesting This is just a View with a button that increments a counter value. The unit test target ExampleAppTests contains a reference image that shows what the view should look like and uses the Snap.swift swift package (https://github.com/skyweb07/Snap.swift) to check that the View draws correctly. If the View doesn't do what it's expected to, you can diff the images to find out what's going wrong (see the ExampleAppSwiftUIViewTesting README.md page for an impression what that looks like). It would be awesome if XCTest would have an API for such image comparisions built in (something like XCTAssertImage so to speak) with Xcode providing tooling to show-the-diff/update reference images. Also, it would be great if you could capture such images without putting the View actually on the screen for faster run times (with SwiftUI I had to put the UIHostingController on the UIWindow to get a image to compare). Also, it would be great if there would be an 'XCUIElement'-like API for unit tests that could be used to simulate events (like, tap on the button and then check the value increments correctly). Last but not least, the reference images are a great tool to assert the state of an UI, but if you have hundreds of them, it gets a bit slow to compare the images; also it takes an effort to keep them up-to-date. I wonder, what could be an alternative to capture the essence of a View rendering? Maybe something like a textual representation of the UI that could be very quickly compared to detect an unexpected change. Or an API to drill down the View tree and look for certain things. Maybe this could work together with the SwiftUI previews. I sometimes wonder if there could be a button in the preview "Add Unit Test" that would capture a visual assertion (as image or in some other form) and create a unit test that checks that it still works as expected.
Posted Last updated
.
Post not yet marked as solved
0 Replies
1.5k Views
Whenever I work on an iOS project with multiple developers working in parallel, I tend to have to spend a lot of time manually merging Xcode project files because the 'xcodeproj' file format causes conflicts that cannot be merged automatically by common merge tools like 'git merge'. I recorded a video showing what I mean and how I currently deal with these kind of conflicts (have a look at the readme of https://github.com/ralfebert/ExampleXcodeGitProject ) Steps to reproduce: Clone https://github.com/ralfebert/ExampleXcodeGitProject Merge the branches change-from-bob and change-from-alice: Both added a file to the Views group which results in a typical conflict that requires manual work. Better tooling support for merging changes would facilitate easier collaboration on Xcode projects. I wish Xcode would have a simpler project file format that's more concise (like the Package.swift for Swift Package Manager libraries) or a tool that could be used with 'git mergetool' that could merge such changes with a semantic unterstanding of the file format. Current workarounds for these issues: Generate the Xcode project using a tool like xcodegen (https://github.com/yonaskolb/XcodeGen#xcodegen) from a simpler file format Use .gitattributes to treat as binary / merge: https://gist.github.com/kiero/1102043 (corrupts xcodeproj occasionally) git mergetool for pbxproj: https://github.com/simonwagner/mergepbx (worked perfectly for quite some time but is not updated any longer and doesn't support newer additions to the Xcode project file format)
Posted Last updated
.
Post marked as solved
2 Replies
2.2k Views
Hi,I am observing a super strange behavior with XCUITest on Xcode 11.1. I have just a storyboard with two UITextFields both with an accessibility indentifier set. I want to type text in both of them:class ExampleUITests: XCTestCase { func testTypingInTextField() { let app = XCUIApplication() app.launch() let field1 = app.textFields["Field1"] field1.tap() field1.typeText("foo") let field2 = app.textFields["Field2"] field2.tap() field2.typeText("bar") } }Typing into the second field fails with the following error with the cursor blinking in the second text field:Failed to synthesize event: Neither element nor any descendant has keyboard focus. Event dispatch snapshot: TextField, label: 'Field2' Element debug description: Attributes: TextField, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2' Element subtree: →TextField, 0x600000cde760, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2' Path to element: →Application, 0x600000cddf80, pid: 50581, label: 'CO2Rechner' ↳Window (Main), 0x600000cddea0, {{0.0, 0.0}, {375.0, 667.0}} ↳Other, 0x600000cddce0, {{0.0, 0.0}, {375.0, 667.0}} ↳Other, 0x600000cdddc0, {{0.0, 0.0}, {375.0, 667.0}} ↳Other, 0x600000cdf020, {{0.0, 0.0}, {375.0, 667.0}} ↳Other, 0x600000cde920, {{10.0, 30.0}, {355.0, 76.0}} ↳TextField, 0x600000cde760, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2' Query chain: →Find: Target Application 'com.example.CO2Rechner' Output: { Application, pid: 50581, label: 'CO2Rechner' } ︎Find: Descendants matching type TextField Output: { TextField, {{10.0, 30.0}, {355.0, 34.0}}, label: 'Field1', value: foo TextField, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2' } ︎Find: Elements matching predicate '"Field2" IN identifiers' Output: { TextField, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2' }If I remove the code to type into field1 it works.I put a simple example project here: https://github.com/ralfebert/CO2Rechner/archive/bug_textfield_uitest.zipWhat do I miss here?Greetings,Ralf
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.5k Views
Hi,I am wondering if there is way in SwiftUI to make the two Text labels the same size so that the text fields align, similar to an 'Equal width' constraint in Auto Layout:Example code:struct FormView: View { @State var name : String = "" @State var birthDate : String = "" var body: some View { VStack { HStack { Text("Name:") TextField("", text: $name) .textFieldStyle(RoundedBorderTextFieldStyle()) } HStack { Text("Date of birth:") TextField("", text: $birthDate) .textFieldStyle(RoundedBorderTextFieldStyle()) } Spacer() } .padding(20) } }Screenshot:https://ralfebert-assets.fra1.cdn.digitaloceanspaces.com/form-equal-width.pngGreetings,Ralf
Posted Last updated
.
Post not yet marked as solved
0 Replies
394 Views
Hi,I cleaned up my tiny & lightweight REST/networking abstraction that I've been using in a few projects and released it as open source library: https://github.com/ralfebert/TinyHTTPIt's very much inspired by TinyNetworking and Siesta, but way more simple. I'll keep it that clean and simple; it's not supposed to support each and every case, but it's supposed to make very common things simple and easy and allow customization/be a good starting point for forking for everything else.I would like to get feedback on the general approach and the API / I'd like to get the code reviewed by a few more developers towards an 1.0 release.Checkout the readme for usage examples and the example project in the repository for a working example project.Greetings,Ralf
Posted Last updated
.
Post not yet marked as solved
2 Replies
2.1k Views
Hi,I found that setting textView.smartQuotesType = .no for a UITextView has no effect under Catalyst - it will replace standard quotes with typographic quotes anyway. Which is a bit annoying for an editor that shows code; the only workaround I found so far is to manually replace the quotes back to their original form:text = text.replacingOccurrences(of: "“", with: "\"").replacingOccurrences(of: "„", with: "\"")Example project for reproducing the issue: https://github.com/ralfebert/TextViewSmartQuotesExampleAnyone got the same issue/found a solution to disable smart quotes under Catalyst?Greetings,Ralf
Posted Last updated
.
Post not yet marked as solved
1 Replies
687 Views
Hi,is there a way to ask NSPersistentCloudKitContainer to refresh/look for remote changes manually?While it would be great if push notifications would work in the simulator so syncing can be tested without multiple actual devices it would be helpful to have a way to manually request a refresh.Greetings,Ralf
Posted Last updated
.
Post marked as solved
3 Replies
8.5k Views
Hi,I am experimenting with SwiftUI and Combine after watching https://developer.apple.com/videos/play/wwdc2019/226/ ( Data Flow Through SwiftUI ).So I created a Publisher to load some data via network call, something like this:var countriesPublisher: AnyPublisher<[Country], Never> = { let urlSession = URLSession.shared let url = URL(string: "https://www.ralfebert.de/examples/countries.json")! return urlSession .dataTaskPublisher(for: url) .map { $0.data } .decode(type: [Country].self, decoder: JSONDecoder()) .assertNoFailure() // todo: no error handling right now .receive(on: RunLoop.main) .eraseToAnyPublisher() }()And I want to use this in a SwiftUI view. Now the WWDC talk recommended to use @State to hold the data, subscribe to it via onReceive and copy it to the internal state. This works, f.e.:struct CountriesListView: View { @State var countries = [Country]() var body: some View { List(countries) { country in Text(country.name) } .onReceive(countriesPublisher) { countries in self.countries = countries } } }(the example project is available here: https://github.com/ralfebert/Countries/archive/ed73ddb5423548d54375f62904d8e81f7f7841d2.zip )Ok, this works and it's pretty cool already. But:I liked the 'single source of truth' principle mentioned in the talk, but this violates it by copying the state. I consider the output of the Publisher to be this source of truth.For the PreviewProvider I'd like to be able to pass in static data, and in that case, I don't want the onReceive to be called.It was recommended to keep @State private which made sense to me, but if I want to move the onReceive() call out / one level up, this cannot be private anymore.Are there any best practices already how to connect a SwiftUI view to such a Publisher?Greetings,Ralf
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.5k Views
I just filed the following suggestion via the Feedback assistant. I'm posting it here for having a URL to refer to / for public discussion. How do you think about this - would you like to have this tiny detail improvement in Xcode as well?When using the code completion to override methods, it would be very helpful if Xcode would automatically generate a call to the super-class implementation of the method.Steps to reproduce:1. Generate a new iOS Project with the Single View application template.2. Open the ViewController class.3. Begin to type viewWillAppear… in the class to override the superclass method.Expected:A method stub with a call to the super method should be inserted:override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) // <- this should be here automatically <#code#> }Actual:A method stub without a call to the super method is inserted:override func viewWillAppear(_ animated: Bool) { <#code#> }
Posted Last updated
.