Skip to content

Instantly share code, notes, and snippets.

View archieedwards's full-sized avatar

Archie archieedwards

View GitHub Profile
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
.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
@archieedwards
archieedwards / YourLibraryView_categorySwipe_SwiftUI.swift
Last active June 9, 2020 14:00
code to enable swiping through categories
.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{
@archieedwards
archieedwards / YourLibraryView_simple_SpotifySwiftUI.swift
Last active June 9, 2020 13:08
base structure for the Your Library view..
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 {
@archieedwards
archieedwards / MediaContentView_SpotifySwiftUI.swift
Created June 9, 2020 11:27
a view to simulate common sub category views..
struct MediaContentView: View {
var colours : [Color] = [.red, .orange, .green, .pink, .purple, .yellow]
var body: some View {
ScrollView(.vertical, showsIndicators: true){
ForEach(0..<10) {_ in
HStack{
Rectangle()
.frame(width: UIScreen.main.bounds.size.width/6 , height: UIScreen.main.bounds.size.height/12)
.foregroundColor(self.colours[Int.random(in: 0 ... 5 )])
VStack(alignment: .leading){
@archieedwards
archieedwards / SubCategoryTextView_SpotifySwiftUI.swift
Last active June 9, 2020 10:58
View to show sub categories and green indicator bar
struct SubCategoryText: View {
var subCategorys : [String]
@Binding var currentSubCategoryIndex : Int
@Binding var indicatorOffset : CGFloat
var body: some View {
HStack{
subCategory(index: 0, parent: self)
subCategory(index: 1, parent: self)
subCategory(index: 2, parent: self)
@archieedwards
archieedwards / CategoryTextView_SpotifySwiftUI.swift
Last active June 9, 2020 21:04
View to show Music and Podcasts ...
struct CategoryText: View {
@Binding var currentCategoryIndex : Int
@Binding var nestedPages : [Int]
var body: some View {
HStack(spacing: 20){
Text("Music")
.font(.largeTitle).bold()
.foregroundColor(self.currentCategoryIndex == 0 ? .primary : .secondary)
.onTapGesture {
self.nestedPages = [0,0]
struct ContentView: View {
@State var alertItem : AlertItem?
var body: some View {
/// button
Button(action: {
self.alertItem = AlertItem(title: Text("I'm an alert"), message: Text("Are you sure about this?"), primaryButton: .default(Text("Yes"), action: {
struct ContentView: View {
@State var alertItem : AlertItem?
var body: some View {
VStack{
/// button 1
Button(action: {
struct AlertItem: Identifiable {
var id = UUID()
var title = Text("")
var message: Text?
var dismissButton: Alert.Button?
var primaryButton: Alert.Button?
var secondaryButton: Alert.Button?
}