0

我已经从 NSCFString 数组的 SQLITE 中获取了数组(比如contactNameList)。我想将contactNameList的对象与Int类型的Id数组(比如bookIdArray)进行比较。谁能指导我。帮助将不胜感激。在此先感谢您:)

代码:

let testDetail_Obj = OfflineDB()

ContactDataArray = testDetail_Obj.fetch_BooksFromSQLite()

    for i in 0..< ContactDataArray.count
    {
        let newItem: Any = ContactDataArray[i] as Any
        contactNameList.addObjects(from: [(newItem as AnyObject).value(forKey: "book_Id") as Any])

        print("contactNameList fetched from db = \(contactNameList)")
    }


bookIdArray = contactNameList    // tried this 

func loadBooks() {

    let v = Constant.DBHandler()
    v.clearDatabase()

    Alamofire.request(Constant.url.getAllBooksUrl, method: .get, parameters: nil, encoding: JSONEncoding.default)
        .downloadProgress(queue: DispatchQueue.global(qos: .utility)) { progress in
        }
        .validate { request, response, data in
            // Custom evaluation closure now includes data (allows you to parse data to dig out error messages if necessary)
            return .success
        }
        .responseJSON {
            response in switch response.result {
            case .success(let JSON):
                if let jsonResult = JSON as? Dictionary<String, AnyObject> {
                    // do whatever with jsonResult
                    let booksJson = jsonResult ["objects"]
                    print("jsonResult In loadBook= \(jsonResult)")
                    let realm = try! Realm()

                    for bookJson in booksJson as! [NSDictionary] {
                        let book = Book()
                        print(bookJson)
                        book.author = bookJson["author"] as! String
                        print("\(String(describing: jsonResult ["author"]))")
                        book.bookImg = bookJson["book_img"] as! String
                        book.bookName = bookJson["book_name"] as! String
                        book.desc = bookJson["description"] as! String
                        book.language = bookJson["language"] as! String
                        book.noOfChapters = bookJson["no_of_chapters"] as! Int
                        book.id = bookJson["id"] as! Int
                        book.timestamp = bookJson["timestamp"] as! String

            if bookIdArray.contains(book.id) {
                                // where, static var bookIdArray = [2,10]
                                book.isHidden = false

}}}}}}

我想显示 ie -> book.isHidden = false ,对于所有其 id 存在于 contactNameList 中的书籍。我已经尝试过

bookIdArray = 联系人姓名列表

但没有按要求获得输出。

4

0 回答 0