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 | |
let anyCancellable = AnyCancellable(Function()) | |
class Function: Cancellable { | |
var function: (() -> Void)? = nil | |
func cancel() { | |
function = nil | |
} | |
func callAsFunction() { | |
function?() |
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 UIKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
setMainQueueKey() | |
} | |
@IBAction func trigger(_ sender: Any) { |
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
class Target { | |
internal init(_ value: Int) { | |
self.value = value | |
} | |
static var current = Target(0) | |
var value:Int | |
func getCode() -> Int { | |
return value * 10 + value | |
} |
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 class UIKit.UITableView | |
import class UIKit.UIView | |
import class UIKit.UIActivityIndicatorView | |
import struct Foundation.IndexSet | |
import struct Foundation.IndexPath | |
import struct UIKit.CGRect | |
import class UIKit.NSLayoutConstraint | |
public protocol PagingTableViewDelegate:AnyObject { | |
func didPaginate(_ pagingTableViewPresenter: PagingTableViewPresenter, to page: Int) | |
func paginate(_ pagingTableViewPresenter: PagingTableViewPresenter, to page: Int) |
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 UIKit | |
extension UIViewController { | |
static func setContainerView<R>( | |
target: R, | |
_ vc:UIViewController, | |
in viewPath: KeyPath<R,UIView>) | |
where R: UIViewController { | |
target.addChild(vc) | |
vc.didMove(toParent: target) | |
target[keyPath: viewPath].addSubview(vc.view) |
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
class GamePlayer: ObservableObject { | |
@Published var exp: Int = 0 | |
@Published var health: Int = 100 | |
} |
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
class UIGamePlayer:GamePlayer, ObservableObject { | |
override var exp:Int { | |
willSet {objectWillChange.send()} | |
} | |
override var health:Int { | |
willSet {objectWillChange.send()} | |
} |
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
class GamePlayer { | |
var exp: Int = 0 | |
var health: Int = 100 | |
} |
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 SomeView: View { | |
@ObservedObject var gamePlayer = UIGamePlayer() | |
var body: some View { | |
Button(action: { | |
self.gamePlayer.exp += 1 | |
}) { | |
Text(gamePlayer.exp.description) | |
} | |
} | |
} |
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
extension Array { | |
func callAsFunction(_ index:Int) -> Element? { | |
indices.contains(index) | |
? self[index] | |
: nil | |
} | |
} |