Skip to content

Instantly share code, notes, and snippets.

View pchelnikov's full-sized avatar
:octocat:
Focusing

Michael Pchelnikov pchelnikov

:octocat:
Focusing
View GitHub Profile
@jordansinger
jordansinger / iPod.swift
Created July 27, 2020 21:19
Swift Playgrounds iPod Classic
import SwiftUI
import PlaygroundSupport
struct iPod: View {
var body: some View {
VStack(spacing: 40) {
Screen()
ClickWheel()
Spacer()
}
import SwiftUI
// Note: There are some issues with using these modifiers inside of ButtonStyles on macOS. Please see https://twitter.com/noahsark769/status/1288256379640139776?s=20 for more info.
struct ConditionalContent<TrueContent: View, FalseContent: View>: View {
let value: Bool
let trueContent: () -> TrueContent
let falseContent: () -> FalseContent
@ViewBuilder var body: some View {
import SwiftUI
import PlaygroundSupport
// NOTE: this example currently only works with US-based coordinates
// constants
// New York
let latitude = 40.709335
let longitude = -73.956558
@jordansinger
jordansinger / macOS.swift
Last active February 14, 2024 03:41
macOS SwiftUI Playgrounds code
import SwiftUI
import PlaygroundSupport
struct Desktop: View {
var body: some View {
ZStack {
// Image(uiImage: #imageLiteral(resourceName: "IMG_6281.JPG"))
Color(UIColor.systemBlue)
macOS()
}
@dsabanin
dsabanin / enable-xcode-debug-menu.sh
Last active November 7, 2022 16:17
Enable internal Xcode debug menu in Xcode 11
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode
sudo touch /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode/AppleInternal.plist
# Don't forget to restart Xcode
@WorldDownTown
WorldDownTown / PropertyWrapperSample.swift
Created December 27, 2019 06:40
Property Wrapper Sample with UserDefaults
// refers to https://qiita.com/imk2o/items/1771682e9665865851e1
import Foundation
protocol UserDefaultConvertible {
init?(with object: Any)
func object() -> Any?
}
extension UserDefaultConvertible {
@rebornix
rebornix / content.swift
Created December 22, 2019 06:21
SwiftUI list view selection & navigation
import SwiftUI
struct Task: Codable, Identifiable, Hashable {
var id: Int
var name: String
}
struct ContentView: View {
@dry1lud
dry1lud / combine-retry.md
Last active November 27, 2023 10:07
Retry operation in Swift/Combine.

There is a function .retry() in Combine that helps to retry a request. Although it is not enough just to call retry() to achieve retring logic. The retry() function does not do another request but it re-subscribes only to a publisher. To make another request the tryCatch() might be used. In the code below if the first call fails there are three attempts to retry (retry(3)):

import UIKit
import Combine
import PlaygroundSupport

enum CustomNetworkingError: Error {
    case invalidServerResponse
}
@beliy
beliy / StretchyHeaderView.swift
Created August 9, 2019 11:11
Source code for the article 'Stretchy header in SwiftUI' (https://jetrockets.pro/blog/stretchy-header-in-swiftui)
//
// ContentView.swift
// StretchyHeader
//
// Created by Alexey Belousov on 01.08.2019.
// Copyright © 2019 JetRockets. All rights reserved.
//
import SwiftUI
@stinger
stinger / CombineFetcher.swift
Last active January 28, 2023 18:07
Combine - fetching data using URLSession publishers
import Foundation
import Combine
enum APIError: Error, LocalizedError {
case unknown, apiError(reason: String)
var errorDescription: String? {
switch self {
case .unknown:
return "Unknown error"