shinonome-inc / mobile_tak848

0 stars 0 forks source link

【最終課題】マイページの作成 #18

Closed TAK848 closed 2 years ago

TAK848 commented 2 years ago
TAK848 commented 2 years ago

URLからクエリ https://stackoverflow.com/questions/41421686/get-the-value-of-url-parameters

もっと便利に https://qiita.com/yamataku29/items/90731a5d148e9b0e2a4e

TAK848 commented 2 years ago

全然関係ないけど,webページとアプリをリンクさせる https://developer.apple.com/documentation/webkit/promoting_apps_with_smart_app_banners

TAK848 commented 2 years ago

AlamofireのURLRequestConvertible,asURLRequestでは,methodを指定するべし https://qiita.com/yimajo/items/23d09734cf5f840bc822 URLRequestConvertible-公式doc https://alamofire.github.io/Alamofire/Protocols/URLRequestConvertible.html#/s:9Alamofire21URLRequestConvertiblePAAE10urlRequest10Foundation0B0VSgvp

こいつの延長 https://qiita.com/yimajo/items/dd0daae1b264570c152d

extension WebAPIRequest {
    // デフォルト実装としてprotoocl extensionsで実装を書いておく
    public func asURLRequest() throws -> URLRequest {
        let request = URLRequest(url: baseURL.appendingPathComponent(path))

        // ここではデフォルトとしてpost, put, patchの場合にJSONでパラメータを送るようにしています。
        // もちろんそれはAPI仕様によって変わりますのでそれぞれの仕様に合わせるのが良いでしょう。
        switch method {
        case .post, .put, .patch:
            return try JSONEncoding.default.encode(defaultIntercept(request), with: parameters)
        default:
            return try URLEncoding.queryString.encode(defaultIntercept(request), with: parameters)
        }
    }
}

extension WebAPIRequest {
    // デフォルト実装としてprotoocl extensionsで実装を書いておく
    public func asURLRequest() throws -> URLRequest {
        var request = URLRequest(url: baseURL.appendingPathComponent(path))
        request.method = method
        // access tokenがあれば足すのもついでに
        if QiitaAccessToken().isExist {
            request.addValue("Bearer " + QiitaAccessToken().value, forHTTPHeaderField: "Authorization")
        }
        // ここではデフォルトとしてpost, put, patchの場合にJSONでパラメータを送るようにしています。
        // もちろんそれはAPI仕様によって変わりますのでそれぞれの仕様に合わせるのが良いでしょう。
        switch method {
        case .post, .put, .patch:
            return try JSONEncoding.default.encode(defaultIntercept(request), with: parameters)
        default:
            return try URLEncoding.queryString.encode(defaultIntercept(request), with: parameters)
        }
    }
}

とすることで,JSONでのPOSTができた methodをここで指定してあげないと,おそらくデフォのget判定でJSONのbodyを作成しようとして,getにbodyは足せんとエラーが出て数時間費やした

TAK848 commented 2 years ago

Swiftで.env

没案

https://qiita.com/sskmy1024y/items/30b25ba5ad8d56448ffc

採用

.envを作成して,さらにURLスキームはInfo.plistを書き換えずに読み込み時のもののみに反映 https://qiita.com/nnsnodnb/items/9344a1955c5cf50e61af https://note.com/rectangle0123/n/n6ad52025b27d

TAK848 commented 2 years ago

WKWebView

本家

https://developer.apple.com/documentation/webkit/wkwebview

基本

【Swift】WKWebViewの基本的な使い方 https://qiita.com/rc_code/items/23109bbb3c073a46eda9 【Swift4】WKWebViewを使ったときに調べたこと https://qiita.com/haru15komekome/items/894ddaa33e1d7aabfe26 WKWebViewについてのまとめ(SwiftUIでの使い方も) https://qiita.com/s_emoto/items/dc3d61626155f5cf83e7 リダイレクト先に応じて https://qiita.com/_mogaming/items/0ed195b79953ec607ea1

-- ちょっとずれて Get the value of URL Parameters https://stackoverflow.com/questions/41421686/get-the-value-of-url-parameters

TAK848 commented 2 years ago

スキーム

https://dev.classmethod.jp/articles/ios-custom-url-scheme/ https://www.dcom-web.co.jp/lab/swift/custom_url_scheme

通常使用で便利に使う https://qiita.com/yamataku29/items/90731a5d148e9b0e2a4e

「URLでアプリを開く」を丁寧に深堀りしていく|toridori(トリドリ)|note https://note.com/toridori_inc/n/nb7237a217a51 URLスキーム・独自ディープリンク実装に代わる、Universal Links(iOS 9で導入)でより良いUXを実現 - Qiita https://qiita.com/mono0926/items/2bf651246714f20df626

TAK848 commented 2 years ago

swiftでもuuid https://qiita.com/addson/items/57e960a556161230de74

TAK848 commented 2 years ago

printするとxbytesとしか表示されない時,とりあえず

String(data: response.request?.urlRequest?.httpBody ?? Data(), encoding: String.Encoding.utf8)

みたいにすると取得できた 後で真面目に勉強 https://stackoverflow.com/questions/45733056/using-alamofire-how-get-response-as-raw-string https://stackoverflow.com/questions/39985299/why-does-swift-print-optional455-bytes

TAK848 commented 2 years ago

NSString https://dev.classmethod.jp/articles/ios-nsstring/

TAK848 commented 2 years ago

データの永続化

https://qiita.com/rsahara/items/4a957c77751cda7d2d16

KeychainVSUserDefaults

https://qiita.com/sachiko-kame/items/261d42c57207e4b7002a https://exgyaruo.com/programming/swift/swift5-keychain-access

Keychain

使いかけてやめた(ライブラリ使おう…ってなったため) https://glassonion.hatenablog.com/entry/2017/02/01/193910 一般Swiftでキーチェーンを使用して機密データを永続化する方法 https://ichi.pro/swift-de-ki-tye-n-o-shiyoshite-kimitsu-de-ta-o-eizokuka-suru-hoho-22176382674540 【swift】アプリを削除してもデータを残す方法 (KeyChain) - JPDEBUG.COM https://jpdebug.com/p/1304399

KeychainAccess 様様

https://github.com/kishikawakatsumi/KeychainAccess

UserDefaults

https://qiita.com/uhooi/items/429cac9b798b9c0937ae

TAK848 commented 2 years ago

起動時にどこいく?

初回起動のみ

https://qiita.com/vbc/items/db2a3a9bcced690104cd

UserDefaultsで動的に

https://qiita.com/kilalabu/items/027ef606d0ec85b920df

SceneDelegateについて

https://re-engines.com/2019/10/03/%E3%80%90swift%E3%80%91ios13-1%E3%80%81xcode11%E3%81%A7scenedelegate%E5%91%A8%E3%82%8A%E3%82%92%E8%A7%A6%E3%81%A3%E3%81%A6%E3%81%BF%E3%81%9F%E3%80%82/

昔はapplicationDelegateで書いていた?

やほー〇〇袋 https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q10220349775 def forum https://developer.apple.com/forums/thread/668595

UIWindow を使用して安全にグローバルなモーダル画面を表示する - Qiita https://qiita.com/KosukeOhmura/items/a3dd4f4678291ddb8a6a

情報復元?

https://teratail.com/questions/160986

TAK848 commented 2 years ago

適当メモ アラート表示 https://qiita.com/funacchi/items/b76e62eb82fc8d788da5 ヘルパーアプリ???Swift: macOSでLaunch at loginを実装する あ,macか https://zenn.dev/kyome/articles/9bbc84f4654986 遷移元画面を透過させる場合に使用するUIModalPresentationStyle.overCurrentContextの注意点 https://qiita.com/hirotakan/items/61bc8ca39714dbc9b301 ローディングインジケーター共通化 https://qiita.com/rymshm/items/5fbff3283c0439e73117 String?をアンラップせずに空文字か判定できるようにしてみた https://qiita.com/417_72ki/items/3c894c9b8fa75c0102ee タブ押したら上へ 余力があれば https://qiita.com/s_higeru/items/0fc28a890e39777d73e9 Xcodeで本番・ステージング・開発などの環境を分ける方法 | モグモグ https://mo-gu-mo-gu.com/ios-scheme-build-settings/ CのライブラリをiOS向けにビルドする - 24/7 twenty-four seven https://blog.kishikawakatsumi.com/entry/2018/12/25/122315 ios - How to instantiate a navigation controller from another view controller? - Stack Overflow https://stackoverflow.com/questions/37992125/how-to-instantiate-a-navigation-controller-from-another-view-controller How to add OR condition in Swift generic where clause? - Stack Overflow https://stackoverflow.com/questions/50782635/how-to-add-or-condition-in-swift-generic-where-clause

TAK848 commented 2 years ago

Segueの変遷(旧情報を見るときに参考 https://dev.classmethod.jp/references/xcode-6-segue/

TAK848 commented 2 years ago

画面を閉じたりする苦労編

swift3で画面遷移で遷移元の画面を閉じる方法 https://teratail.com/questions/74585 【Swift/iOS】遷移元画面への戻り方 | カピ通信 https://capibara1969.com/203/ Swift:別階層のViewControllerの取得 https://zenn.dev/maztak/articles/ffbf2e6892e90e swift ViewController呼び出し後、App delegateから再起動する方法 https://teratail.com/questions/336172 【Swift】画面を全て閉じて、ホーム画面に戻る https://nekokichi2yos2.hatenablog.com/entry/2020/07/29/234050

TAK848 commented 2 years ago

画面のゴニョゴニョ 異なるViewControllerからTabBarControllerへの値渡し[Swift4,Xcode8] https://teratail.com/questions/133738 画面遷移から戻るときに親ビューの画面を更新する方法 - Qiita https://qiita.com/edasan/items/bb21d95b737aa246096d 【Swift】UITabBarControllerでアプリ起動時に指定したタブを表示する https://qiita.com/6bar10/items/14f88679bea2a1fe7cdf

TAK848 commented 2 years ago

デバッグ時にViewの階層を見る!!

デバッグのためにView階層を把握する https://qiita.com/akatsuki174/items/45d4bd7cb150defbf116 【Xcode】Tips: デバッグ時にビュー階層を3D表示する - Qiita https://qiita.com/imchino/items/98501108d453d90688ff

TAK848 commented 2 years ago

UIWindowの領域へ Swift UIWindow 活用術 〜やめよう!最前画面の取得〜 https://techblog.istyle.co.jp/archives/7983

TAK848 commented 2 years ago

毎度おなじみ公式doc https://qiita.com/api/v2/docs

TAK848 commented 2 years ago

mutatingとかの復習 https://qiita.com/shtnkgm/items/3a00117c9b918616d116 Cannot assign to property; 'self' is immutable https://developer.apple.com/forums/thread/18754

この後swift実践入門をまた読み直したぜ!言語使用本読むとだんだん理解が深まってって毎回発見がある!

TAK848 commented 2 years ago

attributedString following, followersボタンに 【Swift】UILabelで単位部分(◯秒・◯cm)の一部文字サイズを変更したい - - 元柔道整復師エンジニアBlog - https://chu-bura.hateblo.jp/entry/swift/20190603 【 iOS】titleがAttributedのUIButtonの文字色を変える https://qiita.com/kazuman519/items/a44af4b6b6f02c5a88a9 ラベルの一部分の色を変える(Swift) https://qiita.com/kumas/items/5eec45ac5a7222aa1bbc 【Swift】NSAttributedString.Keyのまとめ https://www.2nd-walker.com/2021/08/30/swift-list-nsattributedstring-keys/ 【初心者向け】NSAttributedStringをcustomKeyで自在に操る話【Swift 4】 https://qiita.com/ComeYummy/items/fe2a29b432ca4b6b17b2

TAK848 commented 2 years ago

button, labelの文字変更(基本 https://sunnyday-travel-aso-6487.ssl-lolipop.jp/programing/swift/button-label-text-change/

TAK848 commented 2 years ago

color literal推し見つけたけど,ダークモード対応めんどくさくね?共通化…はそれ専用にstruct作ればそんな苦じゃないか…ってことは一つの選択肢としてはあり?Assetはstoryboardでは便利なんだけど…やっぱ基本Assetの方が楽だな,少なくともstoryboard使う限りは(オタクの長文自己完結 colorliteralで全部行く人の記事 https://medium.com/swift-column/color-literal-6223850f7e2c Asset使えるようになったで https://dev.classmethod.jp/articles/xcode-9-asset-catalogs-support-named-colors/

TAK848 commented 2 years ago

処理共通化の世界(迷走中

Extension + protocolで

【Swift】ExtensionとProtocolで処理を共通化する方法 https://hiromiick.com/swift-commonize-function/ [iOS]プロトコルで疎結合に組む方法 ボリューム多め https://qiita.com/netetahito/items/0ee646b69ce5657ebed6

delegate絡み

【Swift】delegate実装の流れ https://zenn.dev/dd_sho/articles/fd75d4d452fa61

★【採用】結局はBaseのclass作って継承しろ(Djangoでもお馴染みだなぁ)

[Swift] カスタムViewのdelegateを共通の処理として汎用的に使いたい https://teratail.com/questions/68371

その他

Swiftをせっかく使うならProtocol Oriented Programmingしたい\ https://matsuokah.hateblo.jp/entry/2017/08/22/070000

TAK848 commented 2 years ago

UITableViewのheader周り

今回の用件で,ユーザーの情報と,投稿記事というバナー的なやつがあり,投稿記事だけ上に固定する必要があった そのため,最初はよくわかんない状態からsection0の頭にheaderをつける方法で,後から理解するには作っていた そして,一緒にスクロールさせるのにGroupedを用いていた。 だがこの設定だと,投稿記事表示が上に固定されない!そのため別の方法を考える長い旅に出ることとなった…

UITableViewでカスタムHeaderを使う方法 https://qiita.com/k-yamada-github/items/b15e6aa34671c562ea34 Header登録の簡素化とか https://xyk.hatenablog.com/entry/2017/01/15/202620

SectionのHeaderでセルみたいに高さをテキスト量とかで可変にするなら delegateでUITableViewAutomaticDimensionを返してやれ!→うまくいった https://teratail.com/questions/153693 kannkeinaiyatu https://teratail.com/questions/214778

最初自分が設定していたheaderとsectionのheader(?←この時点では)は別物だと思っていたので,投稿記事ってやつをなんか別の手段で足すのだと思っていた https://tamappe.com/2019/03/09/2019-03-09-200000/ Viewを作らずにセクションをいじる https://qiita.com/Kon_pippiana/items/a8f804c67f310c1f90cb

上に固定とかで迷走した セクションを使用しているときに固定のuitableviewヘッダーを持つことは可能ですか? https://jpcodeqa.com/q/c1ce663351e2b528e0e97ff948ffd9b0

セクションの基本を確認した 【初心者向け】UITableViewのSection(セクション)の使い方 https://blog.mothule.com/ios/uitableview/ios-uitableview-section-basic

plainにしないとどう頑張っても投稿記事くんを上に固定できないとわかった iOS - Sticky section headers in grouped UITableView with custom cells https://stackoverflow.com/questions/33152955/ios-sticky-section-headers-in-grouped-uitableview-with-custom-cells

とりあえず,やっとtableView全体のheaderが別にあることに気づき始めた? ios - Ungrouping UITableView Section Header when Header is top of view - Stack Overflow https://stackoverflow.com/questions/39802746/ungrouping-uitableview-section-header-when-header-is-top-of-view?rq=1

公式ドキュメント!!!!!

真面目に読み始めた ~(もっと早く読め…~ https://developer.apple.com/documentation/uikit/uitableview var tableHeaderView: UIView?の存在に気づいた!delegateではパッと眺めた限り設定できなそう。こいつにうまいことviewを設定すれば,使い回ししつつ消えてくれるユーザー情報のヘッダーが作れると直感した https://developer.apple.com/documentation/uikit/uitableview/1614904-tableheaderview

ゴニョゴニョやって,高さの可変化にも苦労したが

headerView.translatesAutoresizingMaskIntoConstraints = false

で完了した [iOS] UITableViewのtableHeaderView/tableFooterViewをAutoLayoutに対応 https://qiita.com/fromkk/items/de4cbebb3c39ac3888cc 【初心者向け】UITableViewのヘッダーをカスタマイズする - もちゅろぐ https://blog.mothule.com/ios/uitableview/ios-uitableview-section-header-customize Table header view from .xib https://stackoverflow.com/questions/60697882/table-header-view-from-xib 迷走UIView with manual dynamic height inside auto-layout hierarchy https://pilot34.medium.com/uiview-with-manual-dynamic-height-inside-auto-layout-hierarchy-604b69803de3 結局Change width & height at UIView() https://developer.apple.com/forums/thread/656789

最後の苦労編

tableviewのheaderとセクションのheaderの間に謎の空白ができたので削除するお話 結論

tableView.sectionHeaderTopPadding = 0

迷走objective c - How to remove the blank space at the top of a grouped UITableView? - Stack Overflow https://stackoverflow.com/questions/9932711/how-to-remove-the-blank-space-at-the-top-of-a-grouped-uitableview ピンポンios - Space Between Sections in UITableview - Stack Overflow https://stackoverflow.com/questions/30364067/space-between-sections-in-uitableview

まだ解決していなかった編

この状態だと,UIViewの横幅が小さくなってしまう問題が発生した。正しくは,一番横幅の小さいものに横幅が合わさってしまう問題。そしてなぜかattributedButtonには反映されずはみ出した範囲のボタンは反応しなくなるというバグつき。 image さらに正しくは,横幅が制約なくなってしまう問題。 image 幸運にも同じ問題に遭遇した人がいて,横幅のみ制約を適切に加えてやることで解決した。 https://stackoverflow.com/questions/28079591/using-autolayout-in-a-tableheaderview

    if let yourTableViewHeader = Bundle.main.loadNibNamed(UserInfoView.identifier, owner: self, options: nil)?.first as? UIView {
            yourTableViewHeader.translatesAutoresizingMaskIntoConstraints = false
            userArticlesTableView.tableHeaderView = yourTableViewHeader
            yourTableViewHeader.widthAnchor.constraint(equalTo: userArticlesTableView.widthAnchor).isActive = true
            yourTableViewHeader.centerXAnchor.constraint(equalTo: userArticlesTableView.centerXAnchor).isActive = true
            yourTableViewHeader.topAnchor.constraint(equalTo: userArticlesTableView.topAnchor).isActive = true
        }

治った!多分これでOKなはず!嬉しい! image image image

TAK848 commented 2 years ago

カスタムUIView https://qiita.com/maebaru/items/90f915f82e3d6425cbdc safeareaカスタムUIViewに要らないんですけど?? https://developer.apple.com/forums/thread/87043

TAK848 commented 2 years ago

xibファイルでビューを作成して、ストーリーボードやコードから利用する方法(Swift3編) https://dev.classmethod.jp/articles/xib/ swift - xibで作成したViewのサイズを合わせる処理について - スタック・オーバーフロー https://ja.stackoverflow.com/questions/31732/xib%E3%81%A7%E4%BD%9C%E6%88%90%E3%81%97%E3%81%9Fview%E3%81%AE%E3%82%B5%E3%82%A4%E3%82%BA%E3%82%92%E5%90%88%E3%82%8F%E3%81%9B%E3%82%8B%E5%87%A6%E7%90%86%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6 Autolayout code https://yamatooo.blog/entry/2021/04/13/083000

TAK848 commented 2 years ago

タブバーをつけたり消したり https://www.irohabook.com/swift-tabbar-ishidden

TAK848 commented 2 years ago

公式docをもう少し頼りにしよう

TAK848 commented 2 years ago

Alamofire practice How to make POST, GET, PUT and DELETE requests with Alamofire using Swift | John Codeos - Blog with Free iOS & Android Development Tutorials https://johncodeos.com/how-to-make-post-get-put-and-delete-requests-with-alamofire-using-swift/ ios - How to detect 304 statusCode with Alamofire - Stack Overflow https://stackoverflow.com/questions/41816606/how-to-detect-304-statuscode-with-alamofire

TAK848 commented 2 years ago

継承時の注意,まあちゃんと理解しよう SwiftのエラーについてRedundant conformance of 'mapViewController' to protocol 'MKMapViewDelegate' https://teratail.com/questions/259528

TAK848 commented 2 years ago

Swiftで配列をjoin(結合)して文字列にする方法 | Swift5 入門書-逆引き大全集 https://swift.tecc0.com/?p=160