Having problems trying out the example code in this session

I've copied the code as the video was coming along, and getting this error:

error: type 'any Animal' cannot conform to 'Animal'
note: only concrete types such as structs, enums and classes can conform to protocols
note: required by instance method 'feed' where 'some Animal' = 'any Animal'

is this functionality not yet available in Xcode 14b1?

Which code ? There are billions on the internet. If you don't show, how could we guess ?

You are apparently new to the forum, so read this: https://developer.apple.com/forums/thread/706527

import Cocoa

protocol AnimalFeed {
 static func grow() -> Self
}

protocol Animal {
 associatedtype Feed: AnimalFeed

 func eat(_ food: Feed)
}

struct Hay: AnimalFeed {
 static func grow() -> Self {
  print("growing hay")
  return Hay()
 }
}

struct Pellet: AnimalFeed {
 static func grow() -> Self {
  print("growing pellets")
  return Pellet()
 }
}

struct Horse: Animal {
 func eat(_ food: Hay) {
  print("horse eating \(food)")
 }
}

struct Dog: Animal {
 func eat(_ food: Pellet) {
  print("dog eating \(food)")
 }
}

struct Farm {
 func feed(_ animal: some Animal) {
  let food = type(of: animal).Feed.grow()
  animal.eat(food)
 }

 func feedAll(_ animals: [any Animal]) {
  for animal in animals {
   feed(animal)
  }
 }
}

let animals: [any Animal] = [
 Horse(),
 Horse(),
 Dog(),
]

let farm = Farm()
farm.feedAll(animals)

according to the video, that should compile...

aside: I opened the forum post creator from the Embrace Swift Generics video, which added the tag for the video, so I assumed it would signal which video I was talking about, but I guess the forum is not very useful in that regard

Hope I'm not wrong here. And I would be interested by the correct answer to this post.

You are applying any to a protocol. I read that would only be availabale with Swift 6 (Xcode 14 is Swift 5.7 : https://swiftversion.net/).

However, example given in SE-0352 (implemented in Swift 5.7) tells it is possible

https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md

And you're right, it is very similar to SE-0352, so it should work.

Unless it is not yet in 14 beta ?

If that may help, I noted that this works:

    func feedAll(_ animals: [any Animal]) {
        for animal in animals {
            print("all ->", animal) // feed(animal)
            if animal is Horse {
                feed(Horse())
            }
            if animal is Dog {
                feed(Dog())
            }
        }
    }

This is pretty much copy paste (some unrelated minor modifications) from the referenced video, that mentioned this is available in 5.7 - Xcode 14.

I'm having the same issue with the same XCode beta. I watched the video then tried with my own example and couldn't make it work. Provided sample doesn't work either.

Thank you for reporting this bug! Going into your Xcode build settings, filtering by "Other Swift Flags", and adding -Xfrontend -enable-experimental-opened-existential-types will work around the issue.

I'm unable to reproduce the issue by copy-pasting the complete example code from Embrace Swift Generics at 27:10 into a new command-line macOS tool in Xcode 14 Beta 1. Could you please file a Feedback report, attaching the project and the failed build log, so I can investigate this further? Thank you!

I face to same issue in Playground. Normal Project can compile it.

I had another situation involving SwiftUI with the same error message: Type 'any Identifiable' cannot conform to 'Identifiable'.

I was building on normal project with Xcode 14 beta 2. The project doesn't build with or without the compiler flag -Xfrontend -enable-experimental-opened-existential-types as suggested in prev comment.

import SwiftUI

struct A: Identifiable{
    let id = UUID()
}

struct B: Identifiable {
    let id = UUID()
}

struct ContentView: View {
    let container: [any Identifiable] = [A(), B()]
    var body: some View {
        VStack {
            ForEach(container) { item in
                Text("\(item.id)")
            }
        }
    }
}

Having problems trying out the example code in this session
 
 
Q