View View.swift
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
struct Collapsable<Content: View>: View { | |
@State var collapsed: Bool = true | |
let content: () -> Content | |
init(@ViewBuilder content: @escapin () -> Content) { | |
self.content = content | |
} | |
var body: some View { | |
VStack { |
View filter_keyPath.swift
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
struct Foo { | |
var bar: Int | |
var overThreshold: Bool { | |
bar > 5 | |
} | |
} | |
let fooArray: [Foo] = ... | |
let filtered = fooArray.filter(\.overThreshold) |
View demangler.swift
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 | |
guard CommandLine.arguments.count > 1 else { | |
print("Please specify object file/executable") | |
exit(EXIT_FAILURE) | |
} | |
var nm = Process() | |
nm.launchPath = "/usr/bin/nm" | |
nm.arguments = [CommandLine.arguments[1]] |
View operator.swift
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
extension Effect { | |
// Zip with other effects | |
func zip<Others: Collection>(with others: Others) | |
-> Effect<[Output], Failure> | |
where Others.Element == Effect<Output, Failure> { | |
let first = map { [$0] } | |
.eraseToEffect() | |
return others | |
.reduce(first) { zipped, next in |
View DelegatePublisher.swift
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 Combine | |
import CombineExt // Check this implementation: https://github.com/CombineCommunity/CombineExt/blob/main/Sources/Operators/Create.swift | |
import CoreBluetooth | |
// Client to generate target delegate publisher | |
// Learned from https://github.com/pointfreeco/composable-core-location/blob/main/Sources/ComposableCoreLocation/Live.swift | |
struct PeripheralClient { | |
enum Action: Equatable { | |
case didUptateName |
View Kind.swift
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
// Kind of type | |
public enum Kind { | |
case `struct` | |
case `enum` | |
case optional | |
case opaque | |
case tuple | |
case function | |
case existential | |
case metatype |
View get_pre_main_time.swift
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
/// Call this at main() | |
/// return: time in milliseconds | |
func getPreMainTime() -> Double { | |
let currentTimeIntervalInMilliSecond = Date().timeIntervalSince1970 * 1000.0 | |
var procInfo = kinfo_proc() | |
let pid = ProcessInfo.processInfo.processIdentifier | |
var cmd: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, pid] | |
var size = MemoryLayout.stride(ofValue: procInfo) | |
// Retrieve information of current process | |
if sysctl(&cmd, UInt32(cmd.count), &procInfo, &size, nil, 0) == 0 { |
View Podfile
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
# Add these in your Podfile (available for CocoaPods v1.7.x+) | |
# Replace with any Pods that you want to keep dynamically linked | |
keep_dynamically_linked = ['RxCocoa', 'RxSwift'] | |
target 'YourApp' do | |
# all you pods here... | |
end |
View scan_unused_selectors.swift
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
/* | |
* Note: You need to build this script before use | |
* Usage: | |
* 1. Build by `swfitc scan_unused_selectors.swift` | |
* 2. Run by `./scan_unused_selectors /path/to/yourMachO` | |
* | |
* How to locate MachO of your APP (`/path/to/yourMachO` in above example)? In your Xcod project navigator, you can find a folder `Products` | |
* In that folder you can see your app (after any build) and right click on it -> "Show In Finder" | |
* You can get your APP's location by drag it into your terminal. Say it's "/path/to/MyApp.app", your MachO path would be "/path/to/MyApp.app/MyApp" | |
*/ |
View main.swift
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 UIKit | |
UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, NSStringFromClass(UIApplication.self), NSStringFromClass(AppDelegate.self)) | |
// Remeber to comment or remove `@UIApplicationMain` in your AppDelegate.swift |
NewerOlder