GithubHelp home page GithubHelp logo

aikatsulyric's Introduction

AikatsuLyric

Description

アイカツの歌詞を確認できる iOS アプリ。
完全に個人用のため、配布はなし。

曲一覧 曲詳細
image image

Install

pod install

Contribution

  1. Fork it ( https://github.com/zdogma/AikatsuLyric/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Author

[zdogma](https://github.com/zdogma/)

aikatsulyric's People

Contributors

zdogma avatar

Stargazers

Richard Imaoka avatar

Watchers

 avatar

aikatsulyric's Issues

Song のデータの型(Entity)を定義して持ち回したい

#1 (comment)

持ち回すデータの型(Entity)を定義する

ViewControllerのdataをSong型として定義してあげるとスッキリします。あとJSONマッピングをObjectMapperなどを使ってやるとJSONとEntity間の変換が見通しやすくなりますよ!

import ObjectMapper

struct Song: ImmutableMappable {
    let title: String
    let text: String
    let thumbnail_url: String
    let series: String
    let scene: String
    let singer: String
    let embed_movie_src: String

    init(map: Map) throws {
        title = try map.value("title")
        text = try map.value("text")
        thumbnail_url = try map.value("thumbnail_url")
        series = try map.value("series")
        scene = try map.value("scene")
        singer = try map.value("singer")
        embed_movie_src = try map.value("embed_movie_src")
    }
}
そんでSong型オブジェクトをSongListTableViewControllerとViewControllerで持ち回すようにするといいです。ローカルのJSONファイルから[Song]に変換するメソッドはたとえば次のようになります。

func loadSongs() throws -> [Song] {
    if
        let path = Bundle.main.path(forResource: "aikatsu_songs", ofType: "json"),
        let data = FileManager.default.contents(atPath: path) {
        let json = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as! [[String: Any]]
        return try Mapper<Song>().mapArray(JSONArray: json)
    } else {
        // なにかがおかしいよエラー
        throw CustomError.somethingWrong
    }
}

// どっか別のファイルに定義してもよい
enum CustomError: Error {
  case somethingWrong
}

エラーハンドリングを見直したい

#6

例外の作法

なんつっても例外を握りつぶさないってとこですね。
こちらも参照してみてください。
https://ez-net.jp/article/B2/cwtBwURB/pp3ZiIOQz2Cc/
Result型でのError表現などにも触れられています。

Result型使いたいときは
https://github.com/antitypical/Result
これが良いです。

SwiftLint に則って Caution 対応したい

Caution の数が多そうであれば種類別に PR を分けて対応する。
#1 (comment)

特に
force_cast
force_try
force_unwrapping
をなるべく避けるようにするとよりSwiftらしくなると思います。

例えばこの辺のforce unwrappingを治すとしたら、
var dataを暗黙的アンラップ型で定義して、dataに値が渡ってなかったら非正常系というのを型で表現し、try ~ catchで例外を補足して適当にエラー表示する
Optional Chaining、Optional Bindingを使って、dataにデータが渡されてるとき(正常系)と、渡されてないとき(非正常系)を表示分けする
if let thumbnailUlr = data?.thumbnailUrl, !thumbNailUrl.isEmpty {
// データがあるとき
} else {
// データがないとき
}
のどちらかといった感じです。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.