Skip to content

Instantly share code, notes, and snippets.

@jaclync
jaclync / TestFilterMapCombine.swift
Last active May 24, 2024 06:04
Test mapping to nullable or filtering + mapping
import Combine
struct PointOfSaleEntryPoint {}
let isBetaFeatureEnabled = PassthroughSubject<Bool, Never>()
let isEligibleForPOS = PassthroughSubject<Bool, Never>()
let posViewModel =
Publishers.CombineLatest(isBetaFeatureEnabled, isEligibleForPOS)
// // Map to optional value
// // Output:
@jaclync
jaclync / PickerSelectionTestView.swift
Created October 31, 2023 07:41
Binding a SwiftUI Picker selection to an ObservedObject's @published var
import SwiftUI
class MyData: ObservableObject {
// TIL: the type cannot be optional.
// If the selection type is optional, then the option in the UI & property here won't be binded.
@Published var selectedOption: String = "Option 2"
}
struct PickerSelectionTestView: View {
@ObservedObject var data = MyData()
@jaclync
jaclync / SyntaxHighlighter Code test cases for Swift
Last active March 14, 2022 07:23
Example Swift code for SyntaxHighlighter Code block testing (https://github.com/Automattic/syntaxhighlighter)
<!-- wp:heading -->
<h2>Comments</h2>
<!-- /wp:heading -->
<!-- wp:syntaxhighlighter/code {"language":"swift","lineNumbers":false} -->
<pre class="wp-block-syntaxhighlighter-code">// this is a comment
/* this is also a comment,
but written over multiple lines */
/// This is a function level comment.
///
@jaclync
jaclync / sample_new_order_payload.json
Created September 15, 2021 04:38
Sample WCiOS new order push notification payload
{
"blog": 1600000,
"blog_id": 1600000,
"note_id": 5555555,
"type": "store_order",
"aps": {
"alert": "You have a new order! \Ud83c\Udf89",
"badge": 1,
"category": "store_order",
"content-available": 1,
@jaclync
jaclync / ThreadSafePropertyWrapper.swift
Created September 16, 2020 08:38
Thread-safe property wrapper
@propertyWrapper
public struct ThreadSafe<Value> {
private let queue = DispatchQueue(label: "com.private")
private var value: Value
public init(wrappedValue: Value) {
self.value = wrappedValue
}
public var wrappedValue: Value {
@jaclync
jaclync / example.crash
Created June 23, 2020 00:33
WCiOS Core Data startup crash
Incident Identifier: 1ECDE596-F076-404F-88B2-05475EE63CA3
CrashReporter Key: be1b0e9b09f93fa6569d12c263890cff0e401650
Hardware Model: iPhone11,2
Process: WooCommerce [416]
Path: /private/var/containers/Bundle/Application/DB1A25DA-ADD0-4270-81D8-90B4FC08D5F7/WooCommerce.app/WooCommerce
Identifier: com.automattic.woocommerce
Version: 4.4.0.2 (4.4)
AppStoreTools: 11E608a
AppVariant: 1:iPhone11,2:13
Code Type: ARM-64 (Native)
@jaclync
jaclync / example.crash
Created June 23, 2020 00:28
WCiOS invalid number of rows crashes
Incident Identifier: F727C508-4757-4CED-AC63-C9F2438791B3
CrashReporter Key: bd231a4a42c8098c7b1e343b62f82dee88c4f10b
Hardware Model: iPhone12,1
Process: WooCommerce [5820]
Path: /private/var/containers/Bundle/Application/19FE19D1-2101-4C51-B400-DCF1126475D6/WooCommerce.app/WooCommerce
Identifier: com.automattic.woocommerce
Version: 4.4.0.2 (4.4)
AppStoreTools: 11E608a
AppVariant: 1:iPhone12,1:13
Code Type: ARM-64 (Native)
@jaclync
jaclync / .swift-format
Created October 21, 2019 03:09
`swift-format`: default configurations
{
"blankLineBetweenMembers" : {
"ignoreSingleLineProperties" : true
},
"indentation" : {
"spaces" : 2
},
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineLength" : 100,
@jaclync
jaclync / NMul.java
Created August 31, 2018 02:26
Working version
import java.util.Scanner;
import java.math.*;
public class NMul {
public static void main(String[] args) {
BigInteger sum;
long n;
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
@jaclync
jaclync / Within a mixed framework.md
Last active October 16, 2020 15:33
Swift <--> Objective-C import

Importing Objective-C into Swift

To import a set of Objective-C files in the same framework target as your Swift code, you’ll need to import those files into the Objective-C umbrella header for the framework.

  • Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to “Yes”.
  • In your umbrella header file (FrameworkName.h), import every Objective-C header you want to expose to Swift. For example:
#import <XYZ/XYZCustomCell.h>
#import <XYZ/XYZCustomView.h>
#import <XYZ/XYZCustomViewController.h>