Swift
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…
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…
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 {…
https://techblog.glpgs.com/entry/2023/03/01/165521 UITableViewDiffableDataSource を使ってるときは、 それぞれのA,BのジェネリクスでHashableを実装しておかないといけないようだ。 UITableViewDiffableDataSource<A, B> 以下のエラー Terminating app due to</a,>…
ちょい古いコード 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のオペレーティングシステム(OS)レベルでの「下に引っ張って検索」の機能としては、Spotlight検索が存在します。ユーザーはホーム画面を下にスワイプすることでSpotlight検索バーを開き、アプリ、コンテンツ、ウェブ結果などを検索できます。 ただし、…
/// 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 …
iOS 13から登場した以下の方法 ※今回 _ にしているが、実際の値は(sectionIndex, environment) self.collectionView.collectionViewLayout = UICollectionViewCompositionalLayout { _, _ in // セルの高さ let cellHeight: CGFloat = 54.0 // セルの上下左…
timeIntervalSinceReferenceDate は、iOSのFoundationフレームワークで提供されるメソッドで、2001年1月1日午前0時(UTC)から現在までの秒数を表します。Dartで同じ機能を実現するには、以下のようにして現在の日時を取得し、それを2001年1月1日午前0時(UT…
最後のパスを削除 deletingLastPathComponent /hoge/bar/fuga.dart ↓ /hoge/bar/ になる。最後に'/'はあるっぽい 最後にパス追加 appendingPathComponent /hoge/bar/fuga.dart ↓"bar.dart" /hoge/bar/fuga.dart/bar.dart になる。 /はよしなに これのDart版…
hogeString.suffix(1) hogeString.last!はCharacter?になる
@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…
https://stackoverflow.com/questions/25527311/swift-custom-viewcontroller-initializers
import WebKit final class LimitedWKWebView: WKWebView { // storyboard required init?(coder: NSCoder) { super.init(coder: coder) // 選択をさせない navigationDelegate = self self.scrollView.delegate = self // 平行のインジケーター出さない sel…
future-architect.github.io
混乱するので 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 == …
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…
https://freakycoder.com/ios-notes-13-how-to-change-status-bar-color-1431c185e845 Swiftでヘッダーを色変える
たまにプラグインで必須じゃないメソッドがあるProtocol(インターフェイス)みたいなのをたまに見る。 実装というか準拠先にインターフェイス ※プロトコルの場合は「継承する(させる)」ではなく「準拠する(させる)」 どうやるのか調べた。 https://stackove…
ez-net.jp Any.Type, AnyClassとかある。
Hoge みたいな型を配列として入れたい var nonScorllVCs: [Any.Type] = [Hoge.self] Swift の変数で型を扱う
hogeRecognizer よりも他のtableViewの優先順位を高める const hogeRecognizer = UILongPressGestureRecognizer( target: self, action: #selector(self.hogeMethod) ) みたいな hogeRecognizer がある時 以下のようにする if let gestureRecognizers = tabl…
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…
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 …
https://stackoverflow.com/questions/67925525/async-call-in-a-function-that-does-not-support-concurrency-swift-ios-xcode-asy Task で囲むっぽい そうしないと await できないみたい。
func application( _: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { for item in options.userActivities { if item.activityType == NSUserActivit…
UIProgressBarの色の変更 一見、XcodeのbackgroundColorとtintColorを使うのと思ってしまうが それをやると微妙に色合いが変になる! こいつらは.clearとかにしておく。 https://developer.apple.com/documentation/uikit/uiprogressview 実際のゲージprogre…
Xcodeではできないが、 UITextfieldのplaceholderの色の変更は不可能と思われていたが TextFieldのattributedPlaceholderのパラメーターで可能 self.myTextField.attributedPlaceholder = NSAttributedString( string: "文字", attributes: [NSAttributedStr…
must register a nib or a class for the identifier or connect a prototype cell in a storyboard 右から4番目の「Restoration ID」ではなく、右から3番目の「identifier」