Xcode 11.4 Cast from 'Bool.Type' to unrelated type 'AnyClass' (aka 'AnyObject.Type') always fails - xcode11.4

Since Xcode 11.4, the following code:
override public class func transformedValueClass() -> AnyClass { // What do I transform
return Bool.self as! AnyClass
}
gives a warning: Cast from 'Bool.Type' to unrelated type 'AnyClass' (aka 'AnyObject.Type') always fails
Tried replacing the as! with as, this removes the warning, but the app won't build anymore and the Buildtime displays: error: Segmentation fault: 11
What's going on with Xcode 11.4 and this?

Related

A Swift Tour, compiler error around public property in Protocol and Extensions section

I'm new to Swift and am going through the playground for the official A Swift Tour tutorial. I'm executing the code as-is, but am getting a compiler error when running the following block:
extension Int: ExampleProtocol {
var simpleDescription: String {
return "The number \(self)"
}
mutating func adjust() {
self += 42
}
}
print(7.simpleDescription)
The protocol is defined as follows:
protocol ExampleProtocol {
var simpleDescription: String { get }
mutating func adjust()
}
The compiler error is:
error: Protocols and Extensions.xcplaygroundpage:41:9: error: property 'simpleDescription' must be declared public because it matches a requirement in public protocol 'ExampleProtocol'
var simpleDescription: String {
^
Protocols and Extensions.xcplaygroundpage:41:9: note: mark the property as 'public' to satisfy the requirement
var simpleDescription: String {
^
public
I've tried adding public in front of simpleDescription but then I get an unexpected pattern error.
Anyone know what's going on here?
Turns out although my Xcode version was correctly 12.1, my local Swift version was 5.2.4 (the tutorial assumes 5.3). I installed the Command Line Tools for Xcode 12 package, which updated my Swift to 5.3 and now the code compiled as expected. I used xcrun swift -version to see which version of Swift Xcode was using.

Xcode 10.2 still with Swift 4.2 Array of optional StringProtocol extension not compiling anymore

I've just updated to Xcode 10.2 and my formerly compiling extension can't compile anymore:
extension Array where Element == StringProtocol? {
func joined(by separator: String = " ") -> String {
return compactMap { $0?.description }.joined(separator: separator)
}
}
The famous Protocol 'StringProtocol' can only be used as a generic constraint because it has Self or associated type requirements error now shows up...
Someone can tell me what happened? I have not migrated to Swift 5, just opened my project.
I have changed to:
extension Array where Element == CustomStringConvertible?
But I would like to understand why this changed... Any idea?

Swift 4 : Cannot call value of non-function type '[Self.Element.Type]' when instantiating associated type array

I was doing some exercises on Xcode 9 beta 2 Swift 4 from this article (https://www.uraimo.com/2016/01/06/10-Swift-One-Liners-To-Impress-Your-Friends/) when I came across an error while doing item no. 6:
extension Sequence{
typealias Element = Self.Iterator.Element
func partitionBy(fu: (Element)->Bool)->([Element],[Element]){
var first=[Element]()
var second=[Element]()
for el in self {
if fu(el) {
first.append(el)
}else{
second.append(el)
}
}
return (first,second)
}
}
Xcode 9 was throwing an error in the following lines:
var first=[Element]()
var second=[Element]()
The full error is below:
error: Swift-Playground.playground:6:29: error: cannot call value of non-function type '[Self.Element.Type]'
var second=[Element]()
The error persists even if I remove the typealias and use the full Self.Iterator.Element type.
This code works perfectly on Swift 3. I see no reason why it shouldn't work on Swift 4. Can someone help me out if it's a change in Swift 4 in terms of handling associated types and if so, what's the alternative to instantiate the array.
In Swift 4, protocol Sequence already defines the
associatedtype Element where Self.Element == Self.Iterator.Element
so you can just remove the
typealias Element = Self.Iterator.Element
to make it compile.

Why does compiler warn of unused result on function marked #discardableResult?

The Swift 3 compiler is warning me of an unused result, even though I have marked the function with #discardableResult.
It is only occurring when calling the function on an optional variable, using the ? syntax.
To simplify the problem, I created this sample code. (I had to put it in a project because the warning didn't show in a playground.)
class Foo {
#discardableResult func bar() -> String? {
return "bar"
}
}
class Tester {
func doSomething() {
var foo: Foo?
foo = Foo()
foo?.bar() //Warning: Expression of type 'String?' is unused
foo!.bar() //No warning
}
}
It's a known bug (https://bugs.swift.org/browse/SR-1681), though the Swift gang seems to think it has been resolved. Maybe the fix hasn't made it into Xcode yet, or maybe they're just wrong.
UPDATE We got the official word: The fix will appear starting in Xcode 8.3.

Swift 3 Compiler error: Command failed due to signal: Segmentation fault: 11

I'm trying to extend a Firebase class but am getting a compiler error with the following:
It appears to be related to the failable initialiser but I'm not sure. Is this a bug?
class FIRAuthMock: FIRAuth {
var mockUser: FIRUser
init?(user: FIRUser) {
self.mockUser = user
}
}
Xcode 8.0, Swift 3.0