Skip to content

Instantly share code, notes, and snippets.

@ayusinghi96
Last active February 3, 2026 08:27
Show Gist options
  • Select an option

  • Save ayusinghi96/9d304d703be7eb4f633768c60d887bb0 to your computer and use it in GitHub Desktop.

Select an option

Save ayusinghi96/9d304d703be7eb4f633768c60d887bb0 to your computer and use it in GitHub Desktop.
import Foundation
///
/// A file reader class.
///
/// - Note: Here we will decode JSON data from a static file contaning Movies.
///
final class FileReader {
public static func getMovies(
callback: @escaping (Result<[Movie], FileReaderError>) -> Void)
{
guard let bundleUrlString = Bundle.main.url(forResource: "Movies", withExtension: "json")
else { return }
do {
let data = try Data(contentsOf: bundleUrlString)
let movies = try JSONDecoder().decode([Movie].self, from: data)
callback(.success(movies))
} catch {
callback(.failure(FileReaderError()))
}
}
}
///
/// Error class for file reader.
///
class FileReaderError: Error {
init () {}
func presentError(withKey key: String)
{
print("Error:" + key)
}
}
@Parlamanager123
Copy link

//
// DemoAssistantTests.swift
// DemoAssistantTests
//
// Created by TURAL JABRAYILOV on 15.03.22.
//

import XCTest
@testable import DemoAssistant

class DemoAssistantTests: XCTestCase {

override func setUpWithError() throws {
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
    // Any test you write for XCTest can be annotated as throws and async.
    // Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
    // Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
    // This is an example of a performance test case.
    self.measure {
        // Put the code you want to measure the time of here.
    }
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment