我从SQLITE获取了数组(比如contactNameList),它是NSCFString的数组。我想比较contactNameList的对象和Int类型的数组(比如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
}}}}}}
我想表示即 - &gt; book.isHidden = false,适用于contactNameList中我的id已经尝试的所有书籍。
bookIdArray = contactNameList
但是没有按要求获得输出。