Post

Replies

Boosts

Views

Activity

scale or nativescale? which one to use when you want to round to the nearest pixel?
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?
0
0
828
Dec ’20
Remote Unified Logging after release?
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?
5
0
2.1k
Oct ’20
Where to setup up SKPaymentTransactionObserver?
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?
1
0
589
Oct ’20
How 'persistent' should SKPaymentTransactionObserver be for it to work correctly?
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?
0
0
524
Oct ’20
Swift Bug?
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)
2
0
945
Jan ’20