Skip to content

Instantly share code, notes, and snippets.

View SatoTakeshiX's full-sized avatar

佐藤剛士 SatoTakeshiX

View GitHub Profile
@Amzd
Amzd / StateObject.swift
Last active March 27, 2024 20:14
StateObject that works in iOS 13
import Combine
import PublishedObject // https://github.com/Amzd/PublishedObject
import SwiftUI
/// A property wrapper type that instantiates an observable object.
@propertyWrapper
public struct StateObject<ObjectType: ObservableObject>: DynamicProperty
where ObjectType.ObjectWillChangePublisher == ObservableObjectPublisher {
/// Wrapper that helps with initialising without actually having an ObservableObject yet
@kishikawakatsumi
kishikawakatsumi / TabView.swift
Created November 27, 2019 04:51
My SwiftUI TabView
import SwiftUI
struct TabView: View {
var views: [TabBarItem]
@State var selectedIndex: Int = 0
init(_ views: [TabBarItem]) {
self.views = views
}
@Kuniwak
Kuniwak / Config.xcconfig
Created February 28, 2019 08:25
Useful xcconfig for SwiftSyntax
CUSTOM_SWIFT_SOURCE = $(SRCROOT)/path/to/swift-source
HEADER_SEARCH_PATHS = $(CUSTOM_SWIFT_SOURCE)/swift/include/swift-c/SyntaxParser
LIBRARY_SEARCH_PATHS = $(CUSTOM_SWIFT_SOURCE)/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib
LD_RUNPATH_SEARCH_PATHS = $(LIBRARY_SEARCH_PATHS)
let array = [2, 3, 3, 4, 7, 2, 1, 4, 0, 9, 1, 2]
// array の要素の値ごとに集計
// 2 が 3 個、 3 が 2 個 などを知りたい
let nToCount: [Int: Int] = array.reduce(into: [:]) { nToCount, n in
nToCount[n, default: 0] += 1
}
// 結果を表示
for (n, count) in (nToCount.sorted { $0.key < $1.key }) {
@ezura
ezura / phantom_type.swift
Last active June 15, 2017 09:36
Phantom Type @iosdc
/*:
## Reference
* [Swift: Money with Phantom Types](https://www.natashatherobot.com/swift-money-phantom-types/)
* [Swift で Phantom Type (幽霊型)](http://qiita.com/taketo1024/items/71e3272211f08d7e0cde)
* [Functional Snippet #13: Phantom Types](https://www.objc.io/blog/2014/12/29/functional-snippet-13-phantom-types/)
* [Phantom Typeでコンパイル時に状態チェックする: shibuya.swift #4](https://speakerdeck.com/kazuhiro4949/phantom-typedekonpairushi-nizhuang-tai-tietukusuru-shibuya-dot-swift-number-4)
*/
import Foundation
@andreacipriani
andreacipriani / Bash.swift
Last active February 15, 2024 12:50
Execute shell/bash commands from Swift
import UIKit
protocol CommandExecuting {
func run(commandName: String, arguments: [String]) throws -> String
}
enum BashError: Error {
case commandNotFound(name: String)
}
http://devstreaming.apple.com/videos/wwdc/2016/102w0bsn0ge83qfv7za/102/102_platforms_state_of_the_union.pdf
http://devstreaming.apple.com/videos/wwdc/2016/201h1g4asm31ti2l9n1/201/201_internationalization_best_practices.pdf
http://devstreaming.apple.com/videos/wwdc/2016/202w2zhc4l8yomptqnt/202/202_whats_new_in_accessibility.pdf
http://devstreaming.apple.com/videos/wwdc/2016/203x2w42att1kdzg1ce/203/203_whats_new_in_cocoa.pdf
http://devstreaming.apple.com/videos/wwdc/2016/204t23fvanrkj7a1oj7/204/204_imessage_apps_and_stickers_part_1.pdf
http://devstreaming.apple.com/videos/wwdc/2016/205n2okotvilcayc8rc/205/205_whats_new_in_cocoa_touch.pdf
http://devstreaming.apple.com/videos/wwdc/2016/206a38wgme6uponcuwd/206/206_whats_new_in_tvos.pdf
http://devstreaming.apple.com/videos/wwdc/2016/207i37356qcyyh2yxos/207/207_whats_new_in_foundation_for_swift.pdf
http://devstreaming.apple.com/videos/wwdc/2016/208j30f4v1a1i9i5fg9/208/208_whats_new_in_watchos_3.pdf
http://devstreaming.apple.com/videos/wwdc/2016/209e37d5ks3pfj21ij5/2
@akio0911
akio0911 / CodePiece.swift
Created March 13, 2016 01:10
パターンマッチの例 #swift2 #CodePiece #swift #swiftlang
enum Gender {
case Male, Female
}
enum TimeSaleResult {
case Normal, Morning, Evening
}
func TimeSale(hour:Int) -> TimeSaleResult {
switch hour {
@shinyaohira
shinyaohira / App States and Multitasking.md
Last active October 5, 2023 07:57
アプリケーションの状態とマルチタスキング

全体的に簡略化し、必要と思われる部分を抜粋しました。

  • Not running

    アプリは起動されていないか、実行されていたけれどもシステムによって終了されています。

  • Inactive