Skip to content

Instantly share code, notes, and snippets.

// ...
struct SmallEmojiWidgetView: View {
let emojiDetails: EmojiDetails
var body: some View {
ZStack {
Color(UIColor.systemIndigo)
VStack {
struct EmojibookListView: View {
let emojiData = EmojiProvider.all()
@State private var visibleEmojiDetails: EmojiDetails?
var body: some View {
NavigationView {
List {
ForEach(emojiData) { emojiDetails in
Button(action: {
import Foundation
// Model
struct GuessingGame<GuessElement: Equatable> {
enum GameStatus {
case won
case lost
case playing
}
import Foundation
// ViewModel
class NumberGuessingGame {
private var model: GuessingGame<Int>
private var maxGuesses = 3
init() {
model = GuessingGame(elementToGuess: NumberGuessingGame.generateGuess(), maxGuesses: maxGuesses)
import SwiftUI
struct NumberGuessingGameView: View {
private var gameViewModel: NumberGuessingGame
@State private var guessLabel = "Guess the number!"
@State private var guess = ""
@State private var showAlert = false
import Intents
class IntentHandler: INExtension {
override func handler(for intent: INIntent) -> Any {
// This is the default implementation. If you want different objects to handle different intents,
// you can override this and return the handler you want for that particular intent.
return self
}
}
struct EmojiWidgetView: View {
// ...
}
struct EmojiWidgetPlaceholderView: View {
var body: some View {
Color(UIColor.systemIndigo)
}
}
import SwiftUI
import WidgetKit
struct RandomEmojiWidgetProvider: TimelineProvider {
public func snapshot(with context: Context, completion: @escaping (RandomEmojiEntry) -> ()) {
let entry = RandomEmojiEntry(date: Date(), emojiDetails: EmojiProvider.random())
completion(entry)
}
import SwiftUI
import WidgetKit
struct CustomEmojiWidgetProvider: IntentTimelineProvider {
func snapshot(
for configuration: SelectEmojiIntent,
with context: Context,
completion: @escaping (CustomEmojiEntry) -> ()
) {
import SwiftUI
import WidgetKit
@main
struct EmojiWidgetBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
RandomEmojiWidget()
CustomEmojiWidget()