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 Foundation | |
import PerfectLib | |
import PerfectHTTP | |
import PerfectHTTPServer | |
func setupRouter() -> Routes { | |
var routes = Routes() | |
routes.add(method: .get, uri: "/flights") { request, response in | |
FlightsListController().handleFlightsListRequest(request: request, response: response) |
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 Foundation | |
import PerfectLib | |
import PerfectHTTP | |
import PerfectHTTPServer | |
class FlightsDetailController { | |
func handleFlightsDetailRequest(request: HTTPRequest, response: HTTPResponse) { | |
do { | |
guard let flightId: Int = Int(request.urlVariables["id"] ?? "") else { |
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 Foundation | |
import PerfectLib | |
import PerfectHTTP | |
import PerfectHTTPServer | |
class FlightsListController { | |
func handleFlightsListRequest(request: HTTPRequest, response: HTTPResponse) { | |
do { | |
try response.setBody(json: getFlightsList()) |
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 Foundation | |
func getFlightsList() -> [[String: Any]] { | |
return [ | |
["id":1001, | |
"flightNumber": "AI323", | |
"company": "Air India", | |
"fare": 27637, | |
"stops": 0, | |
"departure":"06:30", |
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 PerfectLib | |
import PerfectHTTP | |
import PerfectHTTPServer | |
let server = HTTPServer() | |
server.serverPort = 3000 | |
do { | |
try server.start() | |
} catch { |
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() | |
setupCollectionView() | |
} | |
func setupCollectionView() { | |
let searchCollectionView = UICollectionView(frame: .zero, collectionViewLayout: getCompositionalLayout()) |
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
@main | |
struct BoxOfficeWidget: Widget { | |
let kind: String = "BoxOfficeWidget" | |
var body: some WidgetConfiguration { | |
StaticConfiguration(kind: kind, provider: Provider()) { entry in | |
BoxOfficeWidgetEntryView(entry: entry) | |
} | |
.configurationDisplayName("Box Office") | |
.description("Box office collection of latest movies") |
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 BoxOfficeWidgetEntryView : View { | |
var entry: Provider.Entry | |
@Environment(\.widgetFamily) var family | |
@ViewBuilder | |
var body: some View { | |
switch family { | |
case .systemSmall: | |
ZStack { | |
moviePosterView() |
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 Provider: TimelineProvider { | |
let dummyData = MovieInfo(name: "Some latest movie", releaseDate: "Release Date", daysSinceRelease: 1, collection: "Collection in Cr", posterUrl: "https://popcornusa.s3.amazonaws.com/placeholder-movieimage.png") | |
func placeholder(in context: Context) -> MovieInfoEntry { | |
MovieInfoEntry(date: Date(), movieInfo: dummyData) | |
} | |
func getSnapshot(in context: Context, completion: @escaping (MovieInfoEntry) -> ()) { | |
let entry = MovieInfoEntry(date: Date(), movieInfo: dummyData) |
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 MovieInfoEntry: TimelineEntry { | |
public let date: Date | |
public let movieInfo: MovieInfo | |
} |