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
// MARK: - UnfairLock | |
final class UnfairLock { | |
private let unfairLock: os_unfair_lock_t //UnsafeMutablePointer<os_unfair_lock> | |
private let unfairValue: os_unfair_lock_s | |
init() { | |
unfairLock = .allocate(capacity: 1) | |
unfairValue = .init() | |
unfairLock.initialize(to: unfairValue) | |
} |
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
class FloatingPanel: NSPanel { | |
init(contentRect: NSRect, backing: NSWindow.BackingStoreType, defer flag: Bool) { | |
// Not sure if .titled does affect anything here. Kept it because I think it might help with accessibility but I did not test that. | |
super.init(contentRect: contentRect, styleMask: [.nonactivatingPanel, .resizable, .closable, .fullSizeContentView], backing: backing, defer: flag) | |
// Set this if you want the panel to remember its size/position | |
// self.setFrameAutosaveName("a unique name") | |
// Allow the pannel to be on top of almost all other windows |
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 SwiftUI | |
import Network | |
final class ViewModel: ObservableObject { | |
@Published var status: NWPath.Status = .satisfied | |
init() { | |
NWPathMonitor() | |
.publisher() | |
.map { $0.status } |
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 struct CoreGraphics.CGSize | |
import struct CoreGraphics.CGPoint | |
import struct CoreGraphics.CGFloat | |
extension CGSize: SIMD { | |
public typealias MaskStorage = SIMD2<CGFloat.NativeType.SIMDMaskScalar> | |
public subscript(index: Int) -> CGFloat { | |
get { | |
index == 0 ? width : height |
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
share() を消すとどうなるか? | |
=> 購読が1本ではなく、2本発生するので、1も2も両方 valueとfinished を無事受け取れる。 | |
Received data 1: 1256 bytes. | |
Received completion 1: finished. | |
Received data 2: 1256 bytes. | |
Received completion 2: finished. | |
これだとPublisherの生成コストがエコではないから、share()を使ってPublisherを struct => class化し、 |
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 SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
AttributedText(getAttributeString()) | |
} | |
func getAttributeString() -> NSAttributedString { | |
let baseString = """ |
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 Combine | |
fileprivate class CancellableStore { | |
static let shared = CancellableStore() | |
var cancellables = Set<AnyCancellable>() | |
} | |
public enum DownloadOutput { | |
case complete(Data) |
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 PlaygroundSupport | |
import SwiftUI | |
import Combine | |
class ObservableObject1: ObservableObject { | |
@Published var name: String = "src" | |
} | |
struct ContentView1: View { | |
@ObservedObject private var object = ObservableObject1() |
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
// This prints a list of buttons that on tap will fire a different type of haptic vibration | |
import SwiftUI | |
struct ContentView: View { | |
let generator = UINotificationFeedbackGenerator() | |
var body: some View { | |
VStack(alignment: .center, spacing: 30.0) { | |
Button(action: { |
NewerOlder