万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    Swift

    Swiftでline-height

    Swiftはこんな基本的なのを用意していない・・・・。 仕方ないので拡張する。 extension UILabel { func applyLineHeight(_ lineHeight: CGFloat) { if let text = self.text, let font = self.font { // NSMutableAttributedStringを使用して、テキストのス…

    フォント一覧

    Swiftでフォント一覧取得 for familyName in UIFont.familyNames { print("Family: \(familyName)") for fontName in UIFont.fontNames(forFamilyName: familyName) { print(" - Font: \(fontName)") } } 結果 Family: Academy Engraved LET - Font: Academy…

    Codableについて

    public struct Hoge: Codable { public var id: Int } 以下のようにもかける public class Hoge: Codable { public var id: Int } struct は値型だが class は参照型 UICollectionViewにてdataSource.apply(snapshot, にて、 SectionとItemにuniqueなIdentif…

    Hashableでidでユニークにならない時

    public class Hoge: Codable { public var id: Int public var name: String // これ追加 let creationDate: Date public enum CodingKeys: String, CodingKey, CaseIterable { case id } // これ追加 required public init(from decoder: Decoder) throws {…

    UITableViewDiffableDataSourceのクラッシュでの修正

    https://techblog.glpgs.com/entry/2023/03/01/165521 UITableViewDiffableDataSource を使ってるときは、 それぞれのA,BのジェネリクスでHashableを実装しておかないといけないようだ。 UITableViewDiffableDataSource<A, B> 以下のエラー Terminating app due to</a,>…

    Swiftのヒラギノのバグ?

    ちょい古いコード https://gist.github.com/takehito-koshimizu/05bd614f980ce7c7d7d2 解説 j gみたいなのではみ出ること。 Decent なのかdescender なのか? https://akisute.com/2016/09/ios.html https://qiita.com/OSR108/items/88f2b3fb6ff8f3c66e3c

    iOSで下に引っ張って検索する機能なんていいますか?あれを使ったアプリ作れますか?

    iOSのオペレーティングシステム(OS)レベルでの「下に引っ張って検索」の機能としては、Spotlight検索が存在します。ユーザーはホーム画面を下にスワイプすることでSpotlight検索バーを開き、アプリ、コンテンツ、ウェブ結果などを検索できます。 ただし、…

    2つのUIViewControllerを交換する拡張メソッド

    /// Swaps the display order of two child view controllers within their parent view controller. /// /// This method is used to adjust the z-ordering of the views associated with two child view controllers. /// It's particularly useful when …

    UICollectionViewCompositionalLayoutはUICollectionViewFlowLayoutと競合するもの

    iOS 13から登場した以下の方法 ※今回 _ にしているが、実際の値は(sectionIndex, environment) self.collectionView.collectionViewLayout = UICollectionViewCompositionalLayout { _, _ in // セルの高さ let cellHeight: CGFloat = 54.0 // セルの上下左…

    timeIntervalSinceReferenceDate をDartで

    timeIntervalSinceReferenceDate は、iOSのFoundationフレームワークで提供されるメソッドで、2001年1月1日午前0時(UTC)から現在までの秒数を表します。Dartで同じ機能を実現するには、以下のようにして現在の日時を取得し、それを2001年1月1日午前0時(UT…

    deletingLastPathComponentやappendingPathComponentのDart版

    最後のパスを削除 deletingLastPathComponent /hoge/bar/fuga.dart ↓ /hoge/bar/ になる。最後に'/'はあるっぽい 最後にパス追加 appendingPathComponent /hoge/bar/fuga.dart ↓"bar.dart" /hoge/bar/fuga.dart/bar.dart になる。 /はよしなに これのDart版…

    Swiftで最後の1文字

    hogeString.suffix(1) hogeString.last!はCharacter?になる

    RxSwiftでアニメーション

    @IBOutlet var mySwitch: UISwitch! で data.boolValue .distinctUntilChanged() .bind(to: mySwitch.rx.isOn) .disposed(by: disposeBag) これだとアニメーションにならない。 .bind(to: mySwitch.rx.isOn) を .subscribe(onNext : { bool in self.mySwitch…

    UIViewControllerを継承して独自initしたい

    https://stackoverflow.com/questions/25527311/swift-custom-viewcontroller-initializers

    LimitedWKWebView

    import WebKit final class LimitedWKWebView: WKWebView { // storyboard required init?(coder: NSCoder) { super.init(coder: coder) // 選択をさせない navigationDelegate = self self.scrollView.delegate = self // 平行のインジケーター出さない sel…

    Swift collection viewの仕組み

    future-architect.github.io

    混乱するBoolのoptional

    混乱するので struct Klass { var a: Bool? = nil var b: Bool? = nil } let klass: Klass? = Klass(a: false, b: nil) let hoge = 3 if klass?.a == false { print("aはfalse") } if hoge == 3 && klass?.a == false { print("aはfalse") } if klass?.b == …

    Swift Concurrencyのasync/await

    tech-blog.optim.co.jp Combineの非同期処理をSwift Concurrencyのasync/awaitで書き換えてみた - ZOZO TECH BLOG https://blog.personal-factory.com/2022/01/23/how-to-use-async-await-since-swift5_5/ WWDC https://developer.apple.com/videos/play/wwd…

    Swiftでヘッダーを

    https://freakycoder.com/ios-notes-13-how-to-change-status-bar-color-1431c185e845 Swiftでヘッダーを色変える

    Swiftの必須ではないProtocol(インターフェス)

    たまにプラグインで必須じゃないメソッドがあるProtocol(インターフェイス)みたいなのをたまに見る。 実装というか準拠先にインターフェイス ※プロトコルの場合は「継承する(させる)」ではなく「準拠する(させる)」 どうやるのか調べた。 https://stackove…

    Any.Type, AnyClass

    ez-net.jp Any.Type, AnyClassとかある。

    Swiftで型の配列を扱う

    Hoge みたいな型を配列として入れたい var nonScorllVCs: [Any.Type] = [Hoge.self] Swift の変数で型を扱う

    タップの優先順位を高める

    hogeRecognizer よりも他のtableViewの優先順位を高める const hogeRecognizer = UILongPressGestureRecognizer( target: self, action: #selector(self.hogeMethod) ) みたいな hogeRecognizer がある時 以下のようにする if let gestureRecognizers = tabl…

    RxSwift asObservable().subscribeと.asDriver().drive違い

    reactive programming - What is the difference between .subscribe and .drive - Stack Overflow xxx.rx.isOn.asObservable() .subscribe(onNext: { [weak self] bool in xxx.rx.isOn.asObservable() .subscribe を asObservable() なしで subscribe xxx.r…

    SwiftでDoubleの型の比較調査

    0 じゃないとだめなのか 0.0でやるか? as Doubleいるかどうか。 let a: Double = 0 if a == 0 { print("== 0") } else { print("== 0じゃない") } if a == 0 as Double { print("== 0 as Double") } else { print("== 0 as Doubleじゃない") } if a == 0.0 …

    awaitとasyncある時に投げっぱなしをswiftで

    https://stackoverflow.com/questions/67925525/async-call-in-a-function-that-does-not-support-concurrency-swift-ios-xcode-asy Task で囲むっぽい そうしないと await できないみたい。

    AppDelegate.swiftでURLから起動の時

    func application( _: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { for item in options.userActivities { if item.activityType == NSUserActivit…

    UIProgressBarの色の変更の注意点

    UIProgressBarの色の変更 一見、XcodeのbackgroundColorとtintColorを使うのと思ってしまうが それをやると微妙に色合いが変になる! こいつらは.clearとかにしておく。 https://developer.apple.com/documentation/uikit/uiprogressview 実際のゲージprogre…

    replacementの灰色背景をOFFにする

    Xcodeではできないが、 UITextfieldのplaceholderの色の変更は不可能と思われていたが TextFieldのattributedPlaceholderのパラメーターで可能 self.myTextField.attributedPlaceholder = NSAttributedString( string: "文字", attributes: [NSAttributedStr…

    cellのエラー

    must register a nib or a class for the identifier or connect a prototype cell in a storyboard 右から4番目の「Restoration ID」ではなく、右から3番目の「identifier」