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
struct YourLibraryView: View { | |
@State var page: Int = 0 //// keeps track of which category index we are at | |
@State var nestedPages: [Int] = [0, 0] /// keeps track of which sub category index we are at for each category | |
@State var indicatorOffsets : [CGFloat] = [0,0] /// keepts track of indicator offsets for each category | |
var data = Array(0..<2) | |
var nestedData = Array(0..<3) | |
var body: some View { |
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
.onPageChanged({ _ in | |
self.allowSubCategoryDragging = true | |
}) | |
.swipeInteractionArea(.allAvailable) | |
.simultaneousGesture(DragGesture().onChanged({value in | |
/// catch moving to category | |
if self.allowSubCategoryDragging { | |
let movingCategoryRight = self.page == 0 && self.nestedPages[self.page] == 2 && value.translation.width < 0 | |
let movingCategoryLeft = self.page == 1 && self.nestedPages[self.page] == 0 && value.translation.width > 0 | |
if movingCategoryRight || movingCategoryLeft{ |
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
.simultaneousGesture(DragGesture().onChanged({value in | |
/// catch moving to category | |
if self.allowSubCategoryDragging { | |
let movingCategoryRight = self.page == 0 && self.nestedPages[self.page] == 2 && value.translation.width < 0 | |
let movingCategoryLeft = self.page == 1 && self.nestedPages[self.page] == 0 && value.translation.width > 0 | |
if movingCategoryRight || movingCategoryLeft{ | |
self.allowSubCategoryDragging = false | |
} | |
else{ | |
let westAsCanBe = self.nestedPages[self.page] == 0 && self.page == 0 && value.translation.width > 0 |
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
public final class NetworkClient { | |
private let session: URLSession = .shared | |
public init() { } | |
func executeRequest(request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) { | |
session.dataTask(with: request) { (data, _, error) in | |
if let error = error { | |
completion(.failure(error)) | |
return |
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
protocol NetworkClientProtocol { | |
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void) | |
} | |
extension URLSession: NetworkClientProtocol{ | |
/// this is where the real request happens | |
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void) { | |
let task = dataTask(with: request) { (data, _, error) in | |
completion(data, error) | |
} |
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
protocol NetworkClientProtocol { | |
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void) | |
} | |
extension URLSession: NetworkClientProtocol{ | |
/// this is where the real request happens | |
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void) { | |
let task = dataTask(with: request) { (data, _, error) in | |
completion(data, error) | |
} |
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
public final class NetworkClient { | |
private let n: NetworkClientProtocol | |
init(n: NetworkClientProtocol = URLSession.shared) { | |
self.n = n | |
} | |
func executeRequest(request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) { | |
n.executeRequest(request: request){ (data, error) in | |
if let error = error { |
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
func testExecuteRequest_failure_noData() throws { | |
/// create mock to return nil | |
class NetworkMock : NetworkClientProtocol{ | |
func executeRequest(request: URLRequest, completion: @escaping (Data?, Error?) -> Void) { | |
completion(nil, nil) | |
} | |
} | |
/// inject mock and execute request |
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
func GetDetails() string { | |
return "wow this is gonna be good" | |
} |
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
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> |