This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
class PlayerTimeObserver { | |
let publisher = PassthroughSubject<TimeInterval, Never>() | |
private var timeObservation: Any? | |
init(player: AVPlayer) { | |
// Periodically observe the player's current time, whilst playing | |
timeObservation = player.addPeriodicTimeObserver(forInterval: CMTime(seconds: 0.5, preferredTimescale: 600), queue: nil) { [weak self] time in | |
guard let self = self else { return } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import AVFoundation | |
struct PlayerTimeView: View { | |
let timeObserver: PlayerTimeObserver | |
@State private var currentTime: TimeInterval = 0 | |
var body: some View { | |
Text("\(Utility.formatSecondsToHMS(currentTime))") | |
.onReceive(timeObserver.publisher) { time in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import AVKit | |
struct VideoView: View { | |
private let player = AVPlayer(url: URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!) | |
var body: some View { | |
VideoPlayer(player: player) | |
.onAppear() { | |
// Start the player going, otherwise controls don't appear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct OCStruct { | |
NSInteger integer; | |
}; | |
@interface OCClass : NSObject | |
- (NSInteger)getInt; | |
- (NSString* _Nonnull)intToStringWith:(NSInteger)integer; | |
- (NSString* _Nullable)tryIntToStringWith:(NSInteger)integer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct SStruct { | |
public var integer: Int | |
} | |
public class SClass: NSObject { | |
@objc public func getInt() -> Int { ... } | |
@objc public func intToString(_ int: Int) -> String { ... } | |
@objc public func tryIntToString(_ int: Int) -> String? { ... } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let address = "[email protected]" | |
let subject = "AwesomeApp Feedback" | |
// Example email body with useful info for bug reports | |
let body = "\n\nApp Version: \(appVersion)\nDevice: \(deviceType)\niOS: \(osVersion)" | |
// Build the URL from its components | |
var components = URLComponents() | |
components.scheme = "mailto" | |
components.path = address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A representation of a playing card | |
struct Card: Identifiable, Equatable { | |
let id = UUID() | |
let number: Int | |
} | |
// A representation of a player's hand of cards | |
class Hand: ObservableObject, Identifiable { | |
let id = UUID() | |
@Published var cards = [Card]() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A representation of the current state of the game, | |
// including which cards each player has and the deck | |
// of cards that can be picked up from | |
class GameState { | |
private(set) var deck = Hand() | |
private(set) var hands = [Hand]() | |
init() { | |
// Fill the deck with 20 cards, shuffled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A view to represent a single card | |
struct CardView: View { | |
let card: Card | |
let namespace: Namespace.ID | |
var body: some View { | |
ZStack { | |
RoundedRectangle(cornerRadius: 20, | |
style: .continuous) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CardView_Previews: PreviewProvider { | |
// Create a wrapper view that will let us hold a @Namespace to pass to the view | |
struct Wrapper: View { | |
@Namespace var animation | |
var body: some View { | |
CardView(card: Card(number: 1), namespace: animation) | |
.padding() | |
.background(Color.gray) | |
} | |
} |
OlderNewer