Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 54297

Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, iPadOS, macOS, watchOS, tvOS, Linux, and z/OS.

2 votes
Accepted

Calculating risk levels

If you need risk level to be an enum (which sounds like good idea anyway), it would be nice to tightly couple the meaning of, say, Risk.Level2 with the range of raw values it represents, such as 1..<5 …
Milos's user avatar
  • 619
7 votes
4 answers
1k views

Typed NSUserDefaults

I was looking around for a Swift wrapper around NSUserDefaults and found some very nice projects (see e.g. SwiftyUserDefaults). Unfortunately, it all boils down to stringy keys galore... …
Milos's user avatar
  • 619
2 votes
2 answers
3k views

Frontmost window of the current application that passes a predicate check

After resigning active state (going to the background), the mainWindow property of the main window in the app returns false. Nevertheless, I need a to find that window even when my app is not active, …
Milos's user avatar
  • 619
1 vote
Accepted

Basic expressive Swift background thread execution

Yes, I see what you mean: there do appear to be dodgy race conditions. I do like where you are going with this, though – dot syntax and all. Still I found at least one failing test. If you paste your …
Milos's user avatar
  • 619
3 votes
1 answer
333 views

Fixed-length Sequences in Swift 2.2

The following is an implementation of fixed-length sequences that makes very exotic (and hopefully fun) use of Swift 2.2 types. …
Milos's user avatar
  • 619
0 votes

Typed NSUserDefaults

1. UserDefault property wrapper (core api) I wish I could go back and edit my first attempt towards “Typed NSUserDefaults”, but that would not be fair to my kind reviewers, so here I’m describing a so …
Milos's user avatar
  • 619
0 votes

Typed NSUserDefaults

2. Going Global - declaring a property only once The single most difficult aspect of persisting data is maintaining the integrity of the data model/format. In the case of the proposed solution towards …
Milos's user avatar
  • 619
0 votes

Typed NSUserDefaults

3. Observing strictly typed user defaults The final piece of the puzzle is a way of easily observing the changes of the underlining value of the UserDefault<T> property. To that end we can introduce t …
Milos's user avatar
  • 619
3 votes

Frontmost window of the current application that passes a predicate check

There is a way of improving the code as desired in that it is possible to constrain the type T to T: NSWindow. Upon introducing this change, however, the function will indeed return the first NSWindow …
Milos's user avatar
  • 619
2 votes

Join 5 optional strings with a joiner character

This is a nice question and the answer by @Airspeed Velocity is an aesthetic experience. I'm afraid the following is unlikely to be to everyone's taste. To begin with, notice that the problem is dom …
Milos's user avatar
  • 619
0 votes

Blocking call to an async function

The proposed approach hangs both on iOS and macOS (just not in unit tests executed in parallel), which is fascinating in its own right. See inline comments: @main struct BlockerApp: App { @St …
Milos's user avatar
  • 619
0 votes

Intersect two ranges in Swift

<string.utf16.count).description ... simply because Character in swift represents extended grapheme clusters, not utf code points. … Swift 3.0 is set to completely rethink indexing throughout the language, so we are yet to see whether we will no longer have to deal with these complexities (unless we explicitly want to). …
Milos's user avatar
  • 619
2 votes
2 answers
4k views

Intersect two ranges in Swift

Can you think of a reason the following extension should not be used in production, or a better way of implementing it: public extension Range { @warn_unused_result public func intersect(oth …
Milos's user avatar
  • 619
3 votes
2 answers
1k views

Blocking call to an async function

While migrating to structured concurrency it may be sometimes convenient to temporarily make a blocking call to an async function - e.g.: let x: Int = try blocking { try await Task.sleep(nanosecon …
Milos's user avatar
  • 619
4 votes
Accepted

Counting words from standard input in Swift

Regarding standard input, see Martin's answer below. As for splitting strings into words and returning them as a sorted dictionary with word counts, that sounds like a useful thing to have around as …
Milos's user avatar
  • 619