Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 模式下取不出模型里的 Int类型的值 #32

Closed
flyuqian opened this issue Nov 8, 2019 · 1 comment
Closed

release 模式下取不出模型里的 Int类型的值 #32

flyuqian opened this issue Nov 8, 2019 · 1 comment

Comments

@flyuqian
Copy link

flyuqian commented Nov 8, 2019

模型

struct BookResource: Convertible {
    enum ResourceType {
        case picture
        case pictureFllowRead
        case video
        case audio
        case demo
        case test
        case weike
        case unkown
    }
    let rID: Int = 0
    let rName: String = ""
    let ext: String = ""
    let showNum: Int = 0
    let fileType: Int = 0
    let chapterID: Int = 9991
    let sectionID: Int = 0
    let downloadPath: String = ""
    let ossName: String = ""
    let picOption: Int = 0
    let imgType: Int = 0
    let fundamentalTone: String = ""
    var type: ResourceType {
        switch picOption {
        case 1:
            if imgType == 1 {
                return .pictureFllowRead
            }
            else {
                return .picture
            }
        case 2:
            return .demo
        case 3:
            return .test
        case 4:
            return .video
        case 5:
            return .audio
        case 6:
            return .weike
        default:
            return .unkown
        }
    }
    func kj_modelKey(from property: Property) -> ModelPropertyKey {
        switch property.name {
        case "rID": return "r_id"
        case "rName": return "r_name"
        case "showNum": return "show_num"
        case "chapterID": return "chapter_id"
        case "sectionID": return "section_id"
        case "imgType": return "img_type"
        case "fundamentalTone": return "fundamental_tone"
        default:
            return property.name
        }
    }
   
}

在这里用的, 我把打印复制到里边了

static func save(bookID: Int, resource: BookResource) {
        dbQueue.inDatabase { db in
            let sql: String = """
            INSERT OR REPLACE INTO t_resource (user_id, book_id, chapter_id, section_id, r_id, r_name, ext, show_num, fileType, downloadPath, ossName, picOption, img_type, fundamental_tone) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
            """
            let resource = resource
            print("resource: \(resource)")
/*            
 resource: BookResource(rID: 984, rName: "situational prompts", ext: "html", showNum: 1, fileType: 2, chapterID: 58, sectionID: 212, downloadPath: "http://114.116.28.196:9003/wap/getSectionContent_984.html", ossName: "getSectionContent_984", picOption: 2, imgType: 0, fundamentalTone: "")
*/

            let resourceID: Int = resource.rID
            
            print("resource.rID: \(resource.rID)")
            print("resourceID: \(resourceID)")
/*
            resource.rID: 0
resourceID: 0
*/

            let arguments: StatementArguments = [userID, bookID, resource.chapterID, resource.sectionID, resourceID, resource.rName, resource.ext, resource.showNum, resource.fileType, resource.downloadPath, resource.ossName, resource.picOption, resource.imgType, resource.fundamentalTone]
            
            print("arguments: \(arguments)")
/*
arguments: [100764, 200121, 9991, 0, 0, "situational prompts", "html", 0, 0, "http://114.116.28.196:9003/wap/getSectionContent_984.html", "getSectionContent_984", 0, 0, ""]
*/
            do {
                try db.execute(sql: sql, arguments: arguments)
            } catch {
                debugLog("save a book resource, 操作异常, error: \(error)")
            }
        }
    }

控制台, 可以把值 po 出来
(lldb) po resource.rID
984

(lldb) po resourceID
0

chapterID, 在使用的时候就是默认值 9991
let chapterID: Int = 9991

@flyuqian
Copy link
Author

flyuqian commented Nov 8, 2019

不好意思,重新看了文档,原来 Int类型不能使用 let。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants