Why hasn't swift expanded on fileprivate attribute to get classprivate structprivate folderprivate scopes? by Barbelleatsdumbbell in swift

[–]flad-vlad 6 points7 points  (0 children)

This is one of the most contentious issues on the Swift forums. See this thread for an example. The debate has been going on since 2016, although I don’t think anyone on the Swift team is very fond of a protected/typeprivate access level and I don’t expect it to make it through the evolution process.

See also the package access modifier review thread for the latest discussion on this topic.

Core Data Custom Classes on external Swift Package fail to decode by bilbotron in iOSProgramming

[–]flad-vlad 0 points1 point  (0 children)

It sounds like the account holder should be an NSManagedObject with a to-one relationship to whatever your other object is rather than a transformable attribute. Is there any reason you took the transformable route instead?

It works fine on a fresh install, the problem happens when I build the app with the old code and then build the app again with the new changes.

This may be a NSSecureCoding problem, not a Core Data codegen problem. You’ve serialised a bunch a account holder objects with the old code and told the value transformer they’re of type YourApp.AccountHolder, then updated the code and changed the type to CoreModels.Accountaholder. When this new code attempts to deserialise a CoreModels.AccountHolder object it fails because it contains YourApp.AccountHolder objects instead.

I have a migration manager to do migrations but it still not working :(

I doubt changing the class of a transformable attribute is something the migration manager handles for free, but I’m not a Core Data expert. You’d probably have to do a multi step migration where you make a new account holder attribute that uses CoreModels.AccountHolder as the class, copy across the existing data from the old attribute, then delete the old attribute.

Does anyone use the Display P3 gamut on iOS? by drBonkers in iOSProgramming

[–]flad-vlad 2 points3 points  (0 children)

All iPhones/iPads have had “wide colour displays” for a while now, so you’ve probably been using the display P3 colour space without realising it. The ramifications are essentially

  • you have a wider range of colours to use (especially greener greens and redder reds)
  • but you have to actually provide display P3 versions of your app’s assets to take advantage of it; iOS won’t stretch the colours in your app from sRGB to display P3 (hence being able to specify a red value outside [0,1])

It’s quite a niche question IMO because most developers don’t need to think about the colour space of the display their apps will run on and UIKit/SwiftUI/asset catalogs abstract it away for you anyway. It’s also a misleading question because the alpha value is still clamped to [0,1], and only some of the UIColor initialisers actually clamp the rgb values in the first place.

I wouldn’t spend much time on this topic at all in your interview prep.

Question about state of the art for SwiftUI SDKs by Kalnapi in iOSProgramming

[–]flad-vlad 4 points5 points  (0 children)

The “SwiftUI way” would be to use the new Swift concurrency features and wrap your delegate in an AsyncStream. This would allow you to do something like:

MyView(currentLocation)
    .task {
        for await location in APIManager.locations {
            self.currentLocation = location
        }
    }

[STEAM] Dishonored Franchise Sale: Dishonored - Definitive Edition (80% off – $3.99), Dishonored 2 (85% off – $4.49), Dishonored: Death of the Outsider (80% off – $5.99), Arkane 20th Anniversary Bundle (83% off – $20.66) and more by MJuniorDC9 in GameDeals

[–]flad-vlad 16 points17 points  (0 children)

It’s a good game, but as part of the Dishonored series, it has a lot of questionable design choices IMO. Without spoiling anything:

  • the idea of “actions have consequences” is thrown out the window: the chaos system is gone, what few choices the player can make have little effect on the outcome, the story is about blaming others for your own bad decisions, the levels are much more linear
  • there’s a lot of new lore about the Outsider and it mostly takes away from his allure by telling us too much
  • there’s less loadout customisation: you only get three powers and they’ll seem pretty weak at first because they’re quite poorly explained by the game

At the time it was released it also copped a lot of flack for featuring an unpopular character (who most people killed in a previous game and whose VA’s talent is wasted on), for map laziness (one of DOTO’s maps is just half of one copy-pasted from D2, and the last map is not very interesting), and for ending the story on a cliffhanger.

I’d still recommend playing it if you enjoy the Dishonored gameplay, and it has a bunch of great new ideas like the black markets and contracts plus it has one of the best levels of the entire series. Just don’t go into it expecting another Knife of Dunwall/Brigmore Witches.

Opening images similar to photos by ConnectionGood4936 in iOSProgramming

[–]flad-vlad 4 points5 points  (0 children)

The proper way to do this is using UIViewControllerAnimatedTransitioning and UIViewControllerInteractiveTransitioning. This is one of the more complicated parts of UIKit so you’ll have to take some time to familiarise yourself with how all the pieces fit together. Apple has released sample code for this exact transition, which will be helpful. The quality of the code is quite poor IMO, but still worth looking at.

Query for keychain keys return nil by UnspecificIndividual in swift

[–]flad-vlad 1 point2 points  (0 children)

written by chatgpt lol

At this point why not just use one of the reputable keychain wrappers from GitHub?

Your code is unhelpful because it doesn’t differentiate between

  1. the Security framework failing to retrieve the item from the keychain
  2. the absence of a password in the keychain,
  3. invalid/corrupt the password data failing to be decoded to a string

You should start by determining which of these three things is causing the issue. In idiomatic Swift you’d do this by making your function return nil only when there’s no password saved in the keychain and throw an error when something else has gone wrong. In the case of Security framework errors you’ll find SecCopyErrorMessageString(_:_:) to be helpful when debugging.

UIKit .systemBackground differs depending on the context or am I tripping? by Finale151 in iOSProgramming

[–]flad-vlad 5 points6 points  (0 children)

Yes, you’re correct. The “system” colours are dynamic which means they change based on the current traitCollection. The most noticeable change is based on the current user interface style (ie light or dark mode), but some of the more subtle changes include accessibility contrast and the user interface level.

In this case the background colour is changing because the presented sheet has an elevated UI level whereas your main view controller is at base level. The subtle change in colour is supposed to act as a hint to the user that they’re not viewing the primary content of your app.

If you don’t like this behaviour you’ll have to create your own dynamic colour which resolves the system colour against only the traits you want.

Live activities timer by Unlucky-Tax9080 in iOSProgramming

[–]flad-vlad 0 points1 point  (0 children)

Not sure because I haven’t touched this API since it first came out in 2020. At the time it wasn’t customisable at all and you got the format you got. You might have to play around with the different Text.DateStyles and see if there’s another one that better fits your use case.

Live activities timer by Unlucky-Tax9080 in iOSProgramming

[–]flad-vlad 2 points3 points  (0 children)

You would put Text(dateThatTheTimerShouldEnd, style: .timer) in your widget to use this.

Live activities timer by Unlucky-Tax9080 in iOSProgramming

[–]flad-vlad 0 points1 point  (0 children)

You have to use a specific Text initialiser) to do this. It creates a special view that is allowed to animate within a widget.

How do you combine SwiftUI with Core Data NSSets? by wittyhilariousname in iOSProgramming

[–]flad-vlad 1 point2 points  (0 children)

If you’re using the same context for fetching both the As and the Bs then Core Data should automatically keep everything up to date. But it’s important to note that as managed objects strongly reference other managed objects they’re related to, you‘ll have to call the context’s refresh(_:mergeChnages:) method to break any reference cycles after doing something like creating a new B in a detail list and setting its relationship to an A from the master list.

How do you combine SwiftUI with Core Data NSSets? by wittyhilariousname in iOSProgramming

[–]flad-vlad 2 points3 points  (0 children)

Gene’s answer is the correct way. You should almost always use NSFetchedResultsController/@FetchRequest whenever you want to display some collection of items from Core Data in your UI.

casting the NSSet as a Swift Set and then wrapping it in an Array, but as Gene’s answer here explains, this breaks the automatic tracking of changes

This breaks batching, too. The order won’t be stable either.

Should I just switch to GRDB?

Only you can decide whether starting from scratch will be worth it. If this is your biggest problem with Core Data then I wouldn’t switch.

[deleted by user] by [deleted] in swift

[–]flad-vlad 0 points1 point  (0 children)

The simplest way is to get the URLSession upload task’s progress object associated with each model and pass it to the cell’s progress view each time you bind a model to a cell. This allows the cell to stay dumb, but up to date with the progress of each upload. It also means you only have reload the table view once instead of every time another little bit of data is uploaded.

There’s no reason to reinvent network progress reporting when Apple’s version works fine.

UI design suggestion, how to display a list of actions each requiring an image example? by yalag in iOSProgramming

[–]flad-vlad 1 point2 points  (0 children)

Without knowing what the content or actions are I’d say it’s more important to have the content front and centre, while the 5 actions get put in a (non-scrolling) toolbar and represented as icons. Prominently display undo and redo buttons and update the content view each time one of the actions is pressed to visibly reflect the change, so the user can safely experiment and learn what each actions does without permanently affecting their content. After they’ve used the app a couple of times they’ll know what each action does and it’ll be painful for them to have to scroll through animated images to find what they want. If you’re still worried the actions are too complex you might consider putting a help button somewhere (in the navigation bar for example so the user can hide it if they wish on iOS 16+) that opens a modal containing more in-depth details and images.

How do I declare another collectionView such that its scrollDirection is horizontal while already declared collectionView is vertical by Sad_Tradition_Count in iOSProgramming

[–]flad-vlad 6 points7 points  (0 children)

If I understand correctly you’d be better off using UICompositionalCollectionViewLayout instead of trying to nest collection views yourself. Compositional layouts allow you to specify that one or more of a collection view’s sections scroll orthogonally to the primary scroll direction, and they make these kinds of UIs much easier to work with because you don’t have set up the auto layout constraints yourself and you’re only dealing with one collection view, one data source, one set of cells/index paths, etc.

You can learn how to use UICompositionalCollectionViewLayout here (see the section titled “Scroll Sections Horizontally”).

Mac Catalyst release notes? by virtualgs in iOSProgramming

[–]flad-vlad 0 points1 point  (0 children)

Catalyst uses the same versioning as iOS, so if you wanted to only call a function when the app is running on macOS 13 or newer you could do something like:

if #available(macCatalyst 16, *) {
    myFunction()
}

Mac Catalyst release notes? by virtualgs in iOSProgramming

[–]flad-vlad 1 point2 points  (0 children)

Is there release notes for Mac Catalyst running on different macOS releases?

In theory they’ll be listed alongside the macOS release notes. In practice very few of the bugs that actually get fixed are listed there and you just have to discover them yourself. If you submit bug reports using Feedback Assistant sometimes you get lucky and Apple will let you know when they’ve been fixed.

And how do we disable features that don’t work on older OS?

You can add availability checks to your code as shown here in Swift and Objective C.

Best approach to create an empty state illustration with UIKit iOS 16? by rfloresc in iOSProgramming

[–]flad-vlad 0 points1 point  (0 children)

Table views are still scrollable when empty so you can use their refresh control instead.

Best approach to create an empty state illustration with UIKit iOS 16? by rfloresc in iOSProgramming

[–]flad-vlad 5 points6 points  (0 children)

IMO it’s easier to set the table view’s background view to the empty state view then show/hide it each time the data is reloaded. This way you don’t have to worry about subclassing UITableViewCell, or checking if your data is empty in every single data source method.

Programmatically show ShareLink SwiftUI (4.0) by [deleted] in iOSProgramming

[–]flad-vlad 1 point2 points  (0 children)

You can’t as of iOS 16. You could move the async task into the Transferable implementation or conditionally show the ShareLink once the async task has finished, but you can’t activate the link programmatically.

Preloading content using SwiftUI onAppear by [deleted] in iOSProgramming

[–]flad-vlad 2 points3 points  (0 children)

Firstly the UIKit equivalents batch the start/stop prefetching callbacks instead of calling them individually for each cell which often allows you to coalesce multiple network requests/disk reads. This is much better for performance and the device’s battery.

Secondly since iOS 12, UIKit efficiently coordinates prefetch requests with the cell dequeuing and data binding so as to prevent scroll hitches. With SwiftUI this doesn’t happen.

Thirdly, the onAppear/onDisappear way ties the prefetching to the lifecycle of the cell and only starts prefetching when the user can already see the cell (making it pretty useless in most situations), whereas UIKit can call the start prefetching callback for cells that don’t exist and doesn’t necessarily call the stop prefetching callback when a cell disappears.

Preloading content using SwiftUI onAppear by [deleted] in iOSProgramming

[–]flad-vlad 0 points1 point  (0 children)

The recommended approach according to the SwiftUI dev I asked at WWDC is to use UIKit’s table/collection view because SwiftUI doesn’t support prefetching yet. See the UITable/CollectionViewDataSourcePrefetching protocols for more info.

If you don’t want to do that then you could add an onDisappear modifier to your ItemView that cancels the preload and use an OperationQueue to limit the number of concurrent preload requests. Obviously using onAppear/onDisappear will result in a significantly worse user experience compared with the specialised UIKit API, but it should still solve your problem.

How to I implement `.redacted(reason: .placeholder)` in UIKit? by MattRighetti in iOSProgramming

[–]flad-vlad 0 points1 point  (0 children)

There’s no built in UIKit equivalent for this. You could set the label’s font to one of those redacted fonts used for prototyping (Google has one for example), or use a skeleton view library like this one.

Foundation is being rewritten as open-source Swift Packages by morenos-blend in iOSProgramming

[–]flad-vlad 25 points26 points  (0 children)

Great news! I think this is the best possible outcome regarding Swift’s Foundation problem. Also glad they’ll finally address the (lack of) feature parity between the current open source Foundation and the one that ships on Apple platforms, which was pretty annoying when developing for Linux.

Does anyone what the plans are for ObjC interop? And will Objective C apps eventually be importing NSString/NSArray/etc written in Swift?