Issue #134 16 May 2019
Written by: Bas Broek
With WWDC coming up in just two and a half weeks time, there is still a lot going on when it comes to Swift.
The top mobile companies like Lyft, Reddit, and EA Games rely on Instabug to iterate faster and enhance their app quality. Instabug lightweight SDK allows developers to receive detailed bug reports directly from testers and users. Instabug attaches screenshots, screen recordings, device details and repro-steps with each report. Try Instabug now - You just need one minute to integrate the SDK! Use the discount-code InstabugLovesSwiftWeekly and get a 20% discount for 3 months on all plans!
Jesse and JP discuss “Removing Things From Swift”, talking about implicit returns and eliding commas.
News and community
Zhuowei Zhang and Max Desiatov worked on initial support for compiling Swift to WebAssembly. 😱
Commits and pull requests
There was a lot of great discussion in this review, leading to some very useful feedback for the Core Team and the proposal authors. That feedback can be broken down into two categories: (1) procedural feedback about the state of the proposal and its review and (2) technical feedback about the actual proposal. Both are useful, and we’ll consider each in turn.
You can read the full post.
Proposals in review
One of Swift’s goals is to be a good language for libraries with binary compatibility concerns, such as those shipped as part of Apple’s OSs. This includes giving library authors the flexibility to add to their public interface, and to change implementation details, without breaking binary compatibility. At the same time, it’s important that library authors be able to opt out of this flexibility in favor of performance.
This proposal introduces “statically” callable values to Swift. Callable values are values that define function-like behavior and can be called using function call syntax. In contrast to dynamically callable values introduced in SE-0216, this feature supports statically declared arities, argument labels, and parameter types, and is not constrained to primary type declarations.
In a nutshell, values that have a method whose base name is
call(referred to as a “
callmethod” for the rest of this proposal) can be called like a function. The function call syntax forwards arguments to the corresponding
I’m a fan of Nate Chandler’s SE-0255 which allows us to omit the
returnkeyword in a single-expression function or computed variables. Here is a case study of SE-0255 as applied to
String’s internal implementation.
Checking some mathematical properties of integers (e.g., parity, divisibility, etc.) is widely used in scientific and engineering applications. While Swift’s standard library provides a convenient method
isMultiple(of:)to test whether an integer is a multiple of another, there are other cases that are not yet supported. A frequently used one is to check if an integer is power of two. This pitch would like to address this problem by adding a computed property
It’s currently unclear without peeking under the hood of swift implementation is the algorithm used for sorting, changes to this algorithm (recently it passed from introsort to timsort) and performances tradeoffs.
Different sorting algorithms might be preferred depending on the problem that needs to be solved. In certain cases it’s important to know that the sorting is stable, in other cases might be important to be sure that the algorithm is in place.
I currently sum the arrays using
.reduce(0,+)which I do not mind by the code is not that readable
Another bigger problem than readability is that I encounter code like this from other developers all the time:
This code might come from imperative thinking but it might also come from not knowing how to use
.reduce()which can look like an intimidating method. A
.sum()would be friendlier and much easier to use even to inexperienced developers.
Currently, if you wish to pass some data to a function that requires the data to conform to a specific protocol, you have to define some type that conforms to the protocol and create an object with that type afterward.
Right now tuples cannot be used as literals to construct structs. Assume there is a function
prettyPrintAsJson(data: Encodable)that you only need to call once in your code. You would define a
class) first and create an instance of that type afterward.
Still going 💪 (puns are the best)