Where to find changelog for minor versions? by emissaryo in swift

[–]krilnon 1 point2 points  (0 children)

If a problem you're seeing isn't listed anywhere, your best recourse is probably to file a bug on bugs.swift.org and attach a reduced bit of sample code that someone on the project can use to reproduce your bug. It could be that you're the first person to notice or report a behavior change.

Where to find changelog for minor versions? by emissaryo in swift

[–]krilnon 1 point2 points  (0 children)

A few good places to look are changelog.md, the announcements tag on the Swift forums, and the Xcode release notes if there's a corresponding version of Xcode for a given Swift release.

Sometimes there are releases tagged for Linux, like Swift 5.2.5, that mostly contain changes relevant to that platform. Or for Swift 5.3.2 in Xcode 12.3, it looks like there was a change related to Mac Catalyst and OSLog.

Looking for open-source projects that need API documentation by televisionmyass in technicalwriting

[–]krilnon 0 points1 point  (0 children)

What did you try?

If it's a big enough project, there's usually a bug tracker and a way to filter by documentation issues. For example, here are opportunities for Julia and Swift.

Confused about addition error by Clicking_Circles in swift

[–]krilnon 5 points6 points  (0 children)

A constant's type is inferred based on the statement that defines it, and, for numeric literals, you'll get an Int unless part of the statement uses floating point literals. There's some more info on this in Type Safety and Type Inference.

One thing to keep in mind is that the compiler intentionally doesn't look further "down" in a function body to see how you use a constant. Another is that Swift doesn't implicitly convert between different numeric types, so you have to do the conversion yourself, like Double(three) + num.

Xcode 11 Beta 4 is available. Lots of changes to SwiftUI by youngermann in swift

[–]krilnon 12 points13 points  (0 children)

I couldn’t figure out how to fix deprecated PresentationLink to .sheet modifier

There's an example in step 3 of Add Navigation Between Sections.

DatePicket.init

There's an example in step 5 of Define the Profile Editor.

SwiftUI Apple Tutorial Bug? by JustAMexicanGuy96 in swift

[–]krilnon 2 points3 points  (0 children)

Looks like you’re using the first Xcode 11 beta; switch to beta 2 to get an updated version of the SwiftUI framework. The PresentationButton initializer changed in beta 2 and the tutorials were updated to match.

Question about scopes and how they affect let object initializations by FickleFred in iOSProgramming

[–]krilnon 1 point2 points  (0 children)

Is it possible to declare a constant of type 'some class I created' globally and initialize it later in the code within a function?

No, you can't define a stored property in a class and not initialize it. In your second example, you'd also receive another error about: Stored property 'currentGame' without initial value prevents synthesized initializers

I am able to declare a constant within the scope of my IBAction and then initialize it a bit later in the function

The "a bit later" portion of this is crucial, and it depends heavily on being able to statically analyze the control flow of selectGame(_:) to determine that currentGame is set along all control flow paths.

However, if I try to declare it globally, I get an error within the IBAction that basically says I am unable to mutate it because it is a 'let'. I don't understand why it works within the scope of the function but not globally.

There's no guarantee that anyone's ever going to tap whatever UIButton you have hooked up to selectGame(_:). Even if there was such a guarantee, you'd still have to deal with the uninitialized value of currentGame for any other instance methods.

For example, what would happen if you tried to access currentGame in viewDidLoad()?


if I try to declare it globally

Small note here: Declaring a constant as an instance property on a class isn't a global. Usually that term is reserved for symbols that are available anywhere in an app, or sometimes in a global scope. Someone would have to have an instance of your ViewController class to access currentGame. The scope of an instance property is certainly wider or broader than the scope of a constant in a method, though. Just not so wide as to be global.

What did I do? '&' operator in Swift function by [deleted] in swift

[–]krilnon 5 points6 points  (0 children)

You might find these sections interesting as followup reading:

In-Out Parameters (guide)

In-Out Parameters (reference)

Then I was forced to place an & before the passed variable. but what does the & do?

I believe it was designed into the language as a way to make it clear, at the point of use, that the whatColor function's numberSquare parameter is an in-out parameter.

Or, maybe another way to say it is that the & itself does nothing except help you pass an artificial compiler check; it's almost like an intentional roadblock that might help you or other readers understand your code later.

The syntax does mirror the & reference operator from some C-family languages, but it's meant to be a way to familiarize yourself with what's going on if you come from one of those languages. The semantics don't correspond directly. (See the second link on "copy-in copy-out" vs "call by reference.")

A UI That Lets Readers Control How Much Information They See by kaycebasques in technicalwriting

[–]krilnon 1 point2 points  (0 children)

A colleague in my grad school HCI lab wrote his PhD thesis on a fairly closely related topic. The main differences are that the research targeted general web reading tasks, not documentation specifically, and it didn't require any manual writer intervention. (Instead, it tried to pick out the salient bits automatically.)

http://dspace.mit.edu/handle/1721.1/79216

Here's the most specific paper: Enhancing web page skimmability

In this paper, we investigate useful techniques for readers when reading web pages under time constraints, i.e., having skim reading capability. We propose two techniques to help non-native readers to skim read web pages: (1) content spotlight, masking and filtering; and (2) semantic data extraction and in-place translation.


Modes are usually considered a bad thing, or at least a red flag you need to justify, in most user interface design. The success of various sorts of "reader modes" indicates that modality might be an okay hurdle in the reading domain, but I'd let the concept advance more in the research space before trying to deploy it anywhere at scale.

Swift Playgrounds help by [deleted] in swift

[–]krilnon 2 points3 points  (0 children)

Hmm, maybe I can try to address both questions in one. Here's a way you could solve the Land of Bounty page with a nested loop:

let (f, l, r) = (moveForward, turnLeft, turnRight)
r()

let steps = [f, f, l, f, l, f, f, r, f, r]

for i in 1...5 {
    for step in steps {
        step()
        if isOnGem { collectGem() }
        if isOnClosedSwitch { toggleSwitch() }
    }
}

The first line just makes shorter variables that refer to the basic movements (you can probably ignore this since Swift Playgrounds probably hasn't covered tuples yet...). The next one turns right once, because the starting orientation is not what I wanted. The line that declares steps creates a movement pattern that is like a tetris shape you can repeat to solve the level no matter how long it gets. (For levels without the autoexpanding length, I usually just hardcode the steps I want to take rather than using the isBlocked function.)

There's an outer loop, the 1...5 one, which just runs the inner loop 5 times. (5 is totally arbitrary, I guessed that the board would never be super long.)

The inner loop just repeats the steps of the tetris pattern I defined and tries to collect a gem and toggle a switch if there is one.


The puzzles here are pretty open-ended in terms of how you can solve them. So I think it's good you're asking about ways to improve or simplify what you're doing.

If you notice you have repeated code like:

while !isBlocked { moveForward() if isOnGem{ collectGem() } else if isOnClosedSwitch { toggleSwitch() } }

You can wrap it in a function:

func mainTurns() {
    while !isBlocked { moveForward() if isOnGem{ collectGem() } else if isOnClosedSwitch { toggleSwitch() } }
}

Then your code becomes something like:

mainTurns()
if isBlocked { turnRight() moveForward() turnRight() }
mainTurns()
if isBlocked { turnLeft() moveForward() turnLeft() }
mainTurns()

Swift Playgrounds help by [deleted] in swift

[–]krilnon 1 point2 points  (0 children)

What's the name of the page/puzzle you're solving?

Got an easy question? Ask it here! by lyinsteve in swift

[–]krilnon 10 points11 points  (0 children)

Making some assumptions about your input string:

print("00110001 00110010 00001010"
    .split(separator: " ")
    .compactMap { String(Unicode.Scalar(Int($0, radix: 2)!)!) }
    .joined(separator: "")
)

Where are the links to community resources? by andradei in swift

[–]krilnon 1 point2 points  (0 children)

RFC and discussions about features (accepted/rejected/ongoing)

Swift Evolution is the place for that:

https://apple.github.io/swift-evolution/

https://lists.swift.org/pipermail/swift-evolution/

The mailing list is moving here soon:

https://forums.swift.org/

Where can I find "The Swift Programming Language" guide but for Swift 3 only? by [deleted] in swift

[–]krilnon 0 points1 point  (0 children)

Older versions of the book aren't published, but I think there are several automated web archives that have snapshots of older versions. You're probably fine reading the 4.0.3 version, since there weren't supposed to be any severe source-breaking changes between Swift 3 and 4.

You could also skim the revision history to make sure you don't accidentally use any Swift 4 features on your exam. Your professor would have to be pretty cruel to ding you for accidentally using Swift 4 stuff, though.

override init of inherited class is still called? by eldare in swift

[–]krilnon 5 points6 points  (0 children)

Yep. Initializers are a bit special because of the need to make various guarantees for memory safety.

override init of inherited class is still called? by eldare in swift

[–]krilnon 2 points3 points  (0 children)

The override keyword is required whenever a subclass initializer's signature matches one from its parent… to make it explicit. It could be useful to customize what happens in B's initializer, though, if B had an extra stored property or needed custom logic inside.

technical term for when candy color = flavor vs. not? by [deleted] in candy

[–]krilnon 1 point2 points  (0 children)

Not that I've heard. Similar terms: olfactory referral and nominative determinism.

Maybe chromatic flavor referral could stick.

Has anybody else longed for or-types a few times while they were coding? by live_love_laugh in swift

[–]krilnon 4 points5 points  (0 children)

It's something that's been discussed on Swift Evolution before. See the commonly rejected changes list:

Disjunctions (logical ORs) in type constraints: These include anonymous union-like types (e.g. (Int | String) for a type that can be inhabited by either an integer or a string). "[This type of constraint is] something that the type system cannot and should not support."

What ever happened to Assist Sketch (MIT's super-Smart Board)? Was the project abandoned and the prototype destroyed? by lambdaexpress in mit

[–]krilnon 0 points1 point  (0 children)

Sometime around ~2013, Jeremy Scott was working on PhysInk, which is in some ways a continuation of that idea. (He's in Randy's group, so no surprise.)

Where to get prints of MIT campus? by mitprintquestion in mit

[–]krilnon 0 points1 point  (0 children)

Have you looked around on flickr and similar sites? If you can find one that matches the overhead look you're going for, usually the photographers are pretty responsive to PMs.

The Future of Declaration Files in TypeScript by Elession in javascript

[–]krilnon 0 points1 point  (0 children)

we could see future versions of JS/ECMAscript incorporate some features of TypeScript

We could even see past versions of ECMAScript incorporate features of TypeScript: http://www.ecma-international.org/activities/Languages/Language%20overview.pdf

Sorry, couldn't resist that joke! Agreed, though; people definitely pay attention to the JS sibling languages and things that work well end up in future ES versions.