New Widget Warning with latest Xcode Beta

Hi all,
I'm getting a new warning which says:

init(kind:provider:placeholder:content:)' is deprecated: use init(kind:provider:content:) instead

Which I changed according to the above, then got:

Incorrect argument label in call (have 'kind:provider:content:_:', expected 'kind:provider:placeholder:content:')

Tried to look in the Widget docs and they aren't updated yet.

Thanks,
Dan Uff


Answered by Documentation Engineer in 623068022
It doesn't look like you've changed the initialization of the StaticConfiguration to remove the placeholder: parameter. That was removed in Beta 3. Instead you need to add an implementation of placeholder(with:) to the Provider. I just posted some details in this thread: https://developer.apple.com/forums/thread/655182. See if that doesn't help get things back on track.
Can you post your code that you're using?
Sure, in a few mins. Thanks.
Here you go:

import Foundation
import WidgetKit
import SwiftUI

struct Provider: TimelineProvider {
    public typealias Entry = SimpleEntry

    public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) {
        let entry = SimpleEntry(date: Date())
        completion(entry)
    }

    public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
        var entries: [SimpleEntry] = []
      
      
      
        // Generate a timeline consisting of five entries an hour apart, starting from the current date.
        let currentDate = Date()
        for hourOffset in 0 ..< 1 {
          let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
            let entry = SimpleEntry(date: entryDate)
            entries.append(entry)
          
          let currentDate = Date()
          let formatter = DateFormatter()
          formatter.dateStyle = .short
          let dateTimeString = formatter.string(from: currentDate)
          print("\(dateTimeString)")
          
          
          
          
        }

      let timeline = Timeline(entries: entries, policy: .atEnd)
        completion(timeline)
    }
}

struct SimpleEntry: TimelineEntry {
    public let date: Date
  
    // future code.
  
  
}

struct PlaceholderView : View {
  
  
    var body: some View {
      
      ZStack {
        
        Color.black
        
          .edgesIgnoringSafeArea(.all)
        
        Text("----- --:")
          .background(Color.black)
          .foregroundColor(Color.white)
          .font(.custom("DIN Alternate-Bold", size: 25))
          .multilineTextAlignment(.center)
        
        Text("--------- -- ----")
          .background(Color.black)
          .foregroundColor(Color.white)
          .font(.custom("DIN Alternate-Bold", size: 25))
          .multilineTextAlignment(.center)
        
        
    }
    }

struct CPClockWidgetEntryView : View {
  
  static var dateformatter: DateFormatter =
    {
      let dateformatter = DateFormatter()
      dateformatter.dateStyle = .medium
      return dateformatter
    }()
  
    var currentDate = Date()
  
  var entry: Provider.Entry
  
   var body: some View {
    
    
    
    ZStack {
      
      Color.black
      
        .edgesIgnoringSafeArea(.all)
      
    VStack {
            Text("Today Is:")
              .background(Color.black)
              .foregroundColor(Color.white)
              .font(.custom("DIN Alternate-Bold", size: 25))
              .multilineTextAlignment(.center)
      
            
            let dateTimeString = PlaceholderView.CPClockWidgetEntryView.dateformatter.string(from: currentDate)

            Text("\(dateTimeString)")
            .background(Color.black)
            .foregroundColor(Color.white)
            .font(.custom("DIN Alternate-Bold", size: 30))
            .multilineTextAlignment(.center)
      
      
}
      
    }
      
    
   }
  
  // <--- Multiple Widgets Code --->

//  struct CPClockWidget: View {
//    @Environment(\.widgetFamily) var family: WidgetFamily
//
//    @ViewBuilder
//
//    var  body: some View {
//
//    switch family {
//    case: .systemSmall(CPClockWidget)
//
//    }
//    }
//  }
//
//}
}


@main
struct CPClockWidget: Widget {
    private let kind: String = "CPClockWidget"

    public var body: some WidgetConfiguration {
      StaticConfiguration(kind: kind, provider: Provider(), placeholder: PlaceholderView()) { entry in
            CPClockWidgetEntryView(entry: entry)
        }
        .configurationDisplayName("CP Clock")
        .description("Widget for CPClock.")
        .supportedFamilies([.systemSmall, .systemMedium])
        
      
      
    }
  
  
  
}

}

struct CPClockWidget_Previews: PreviewProvider {
  
  
  
  static var previews: some View {
    
    
    
    ZStack {
      
      Color.black
      
        .edgesIgnoringSafeArea(.all)
      
      
        VStack {
        Text("Today Is:")
        .background(Color.black)
        .foregroundColor(Color.orange)
        .font(.custom("Arial-Bold", size: 25))
          
        
       
        Text("\(Date(), style: .date)")
        .background(Color.black)
        .foregroundColor(Color.orange)
        .font(.custom("Arial-Bold", size: 30))
        .multilineTextAlignment(.center)
          
    }
    }
    
    .previewContext(WidgetPreviewContext(family: .systemMedium))
  }
}

  func getinfo()
  {
    
  }



Accepted Answer
It doesn't look like you've changed the initialization of the StaticConfiguration to remove the placeholder: parameter. That was removed in Beta 3. Instead you need to add an implementation of placeholder(with:) to the Provider. I just posted some details in this thread: https://developer.apple.com/forums/thread/655182. See if that doesn't help get things back on track.
Yes, that worked. THANK YOU!
New Widget Warning with latest Xcode Beta
 
 
Q