This file contains hidden or 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
| // You have a very very large video file you need to upload to a server while your app is backgrounded. | |
| // Solve by using URLSession background functionality. I will here use Alamofire to enable multipart upload. | |
| class Networking { | |
| static let sharedInstance = Networking() | |
| public var sessionManager: Alamofire.SessionManager // most of your web service clients will call through sessionManager | |
| public var backgroundSessionManager: Alamofire.SessionManager // your web services you intend to keep running when the system backgrounds your app will use this | |
| private init() { | |
| self.sessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.default) | |
| self.backgroundSessionManager = Alamofire.SessionManager(configuration: URLSessionConfiguration.background(withIdentifier: "com.lava.app.backgroundtransfer")) |
This file contains hidden or 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 ItemsViewController: UIViewController { | |
| @IBOutlet private weak var tableView: UITableView! | |
| private let viewModel = ItemsViewModel() | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| bindViewModel() | |
| viewModel.fetchData() | |
| } |
This file contains hidden or 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 DataBinding<T> { | |
| typealias Handler = (T) -> Void | |
| private var handler: Handler? | |
| var value: T { | |
| didSet { | |
| self.handler?(value) | |
| } | |
| } | |
This file contains hidden or 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 DataBinding<T> { | |
| typealias Handler = (T) -> Void | |
| private var handler: Handler? | |
| var value: T { | |
| didSet { | |
| self.handler?(value) | |
| } | |
| } | |
This file contains hidden or 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 ItemsViewModel { | |
| var items = DataBinding<[ItemModel]>(value: []) | |
| var error = DataBinding<Error?>(value: nil) | |
| func numberItems() -> Int { | |
| return items.value.count | |
| } | |
| func fetchData() { |
This file contains hidden or 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 Bond | |
| import ReactiveKit | |
| class UserProfileViewModel { | |
| let refreshing = Observable<Bool>(false) | |
| let username = Observable<String>("") | |
| let photos = Observable<[Photos]>([]) | |
| private let userViewModel: UserViewModel | |
| private let photosViewModel: PhotosViewModel |
This file contains hidden or 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
| var mediaJSON = { "categories" : [ { "name" : "Movies", | |
| "videos" : [ | |
| { "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org", | |
| "sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ], | |
| "subtitle" : "By Blender Foundation", | |
| "thumb" : "images/BigBuckBunny.jpg", | |
| "title" : "Big Buck Bunny" | |
| }, | |
| { "description" : "The first Blender Open Movie from 2006", | |
| "sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ], |
This file contains hidden or 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 | |
| struct PhotoView: View { | |
| @State var scale: CGFloat = 1 | |
| @State var scaleAnchor: UnitPoint = .center | |
| @State var lastScale: CGFloat = 1 | |
| @State var offset: CGSize = .zero | |
| @State var lastOffset: CGSize = .zero | |
| @State var debug = "" |
This file contains hidden or 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 | |
| struct TabBarDemo: View { | |
| @StateObject var tabItems = TabItems() | |
| var body: some View { | |
| ZStack { | |
| ///View1 | |
| NavigationView { | |
| ZStack { |
This file contains hidden or 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
| // | |
| // ContentView.swift | |
| // ios14-demo | |
| // | |
| // Created by Prafulla Singh on 23/6/20. | |
| // | |
| import SwiftUI | |
| struct ChipsDataModel: Identifiable { | |
| let id = UUID() |
OlderNewer