Posts

Post marked as solved
4 Replies
13k Views
I would like to center align the text inside a TextField. I just couldn't find a way to do it. I know in UIKit you could domytext.textAlignment = .rightCould anyone post the equivenant of this in SwiftUI please?
Posted Last updated
.
Post not yet marked as solved
0 Replies
696 Views
I am trying to draw a grid inside a SwiftUI view. I am using Path with 'move(to' 'addLine(to' etc. I am trying to adjust the position of the lines to the nearest pixel to avoid anti-aliasing. At first I had a plan line this.         let positionX: CGFloat = start.x         let scaleFactor = UIScreen.main.scale         let posInPixels = positionX * scaleFactor         let posRoundedToNearestHalfPixel = Int(round(posInPixels * 2))                 let adjustByHalfpixel: Bool         if posRoundedToNearestHalfPixel.isMultiple(of: 2) {             /*that means we have a whole number of pixels, which means we are between pixels so add half a pixel*/             adjustByHalfpixel = true         } else {             /*we have a postion that is already on a pixel so no need to adjust*/             adjustByHalfpixel = false         }         let finalValueInWholePixels = CGFloat(posRoundedToNearestHalfPixel + (adjustByHalfpixel ? 1 : 0))/CGFloat(2)         let finalAdjjustedValueInPoints = finalValueInWholePixels / scaleFactor What I am not sure about is the scale factor Should I use UIScreen.main.scale or UIScreen.main.nativescale ? It is not clear from the documentation what the difference is between those two?
Posted Last updated
.
Post not yet marked as solved
1 Replies
459 Views
The apple document about “Setting Up the Transaction Observer for the Payment Queue” says It is important to add the observer at launch, in application:didFinishLaunchingWithOptions:, to ensure that it persists during all launches of your app, receives all payment queue notifications, and continues transactions that may be processed outside the app, such as: Promoted in-app purchases Background subscription renewals Interrupted purchases In my case, If I received a ‘purchased’ or ‘restored’ event I need to ‘unlock’ the content. This involves doing something in my CoreData Stack. I am setting up the coreData stack (making the NSPersistentContainer, loadPersistentStores  etc.) and setting up a few related objects  in my initial View Controller (in viewdidload) So I am doing pretty early, as soon as the app is launched but not inside the didFinishLaunchingWithOptions. Is that OK? Because my problem is, if I am to do this inside didFinishLaunchingWithOptions, I am not ready to unlock stuff yet because my CoraData stack isn’t ready yet.   I can move my CoreData setup code into didFinishLaunchingWithOptions as well. But when I do this in the first viewController, I can show a spinner to the user to show something is going on. It is not an awful lot of time but could take a second or two. What would be  the ‘Best Practice’ in this case please?
Posted Last updated
.
Post marked as solved
5 Replies
1.7k Views
I am looking for a logging solution that is usable after the app is released to help keep track of errors etc. Does the Apple "Unified Logging" allow you to do this? After a quick glance at the documentation it is not clear how I can view logs after release. If not is there any 'Apple way' of monitoring logs after release without having to use a third party solution like Firebase?
Posted Last updated
.
Post not yet marked as solved
0 Replies
421 Views
I have a question about in App purchases and the SKPaymentTransactionObserver The apple document here says “The observer must be persistent so it is not deallocated when the app is sent to the background. Only a persistent observer can receive transactions that may occur while your app is in the background, such as a renewal transaction for an auto-renewable subscription.” The link is here  https://developer.apple.com/documentation/storekit/in-app_purchase/setting_up_the_transaction_observer_for_the_payment_queue?language=objc  My question is what they mean by ‘persistent’ I am guessing, as long as the observer is kept in memory (with at least one strong reference to it somewhere) it will ‘persist’?  I am assuming that while the app goes into the background, nothing gets deallocated unless we as developers do that deliberately in the Application will Resign active or applicationDidEnterBackground etc. Of course after a while, the app could be suspended and everything will get cleared out including our SKPaymentTransactionObserver. I guess we don’t have to worry about this? Or does the apple document mean we should persist the observer object on disk? Using NSCoder or Codable or something? and bring it back to life when the app is launched again? I am guessing no because even if we do that, that is simply going to save the properties  to file and create a new object with the same properties. And SKPaymentTransactionObserver doesn’t even have any properties  - only methods So if the app gets suspended or if the user kills it etc. we are going to create a new instance of the transaction observer and that is OK? Am I right here?
Posted Last updated
.
Post marked as solved
2 Replies
769 Views
The function below should print 25 pairs of numbers which works fine. Now uncomment the commented line and the combination 2,4 is missing. I am using XCode 11. Tried this on playground as well as in an Xcode project (command line utility)func solve(arr: [Int]) -> Int { for i in arr.indices { for j in arr.indices { print("i is \(i) j is \(j)") // guard i < j else { // continue // } // let (x,y) = (arr[i] , arr[j]) // guard (x * y) <= arr[i...j].max()! else{ // break // } } } return 0 } let a: [Int] = [1, 1, 2, 4, 2] solve(arr: a)
Posted Last updated
.
Post not yet marked as solved
1 Replies
716 Views
I used to know this until Beta5 came along. Now it needs a PrimitiveButtonStyleConfiguration.Label but I am not sure how to initialise a PrimitiveButtonStyleConfiguration.Label? Previously we were able to put any old view as a Label. But not anymore.
Posted Last updated
.
Post marked as solved
4 Replies
6.9k Views
I have a hierarchy of views. The top level view has an @Binding property. I am wondering what is the best practice when it comes ot providing the intial value for this Binding?The original value ( Or source of truth) should be in some model I guess. But I am not sure where the original value should be created and how this should be passed onto the view. Suppose we have a model object that 'owns' this value. The model object should provide the inital value for this. But how do you create an inital value for an @Binding variable? You could use .constant(Value) but that seem to create an immutable value. How do you create a mutable @Binding with an intial value?
Posted Last updated
.
Post marked as solved
5 Replies
2.0k Views
Hi,I have a class or a struct and I would like to make my own publisher that watches a property or the class and publishes its value everytime it changes.The only way I can think of is to creata a pass through subject and then call 'send' on it everytime the property changes (in the didSend)but I have a feeling there is probably a better pattern for this that I might be missing? Is there a better way to acheive this? Is there something like the opposite of 'Assign'? that lets you publish changes to a property?
Posted Last updated
.