类型“ AnyObject”的值没有成员“ prefix”;您是说“精确”吗?

时间:2018-10-31 11:04:13

标签: arrays swift tableview uisearchbar

我在我的swift应用中实现了搜索功能,但出现了这样的错误

错误 类型“ AnyObject”的值没有成员“ prefix”;你是说“精确”吗?

我正在调用api,并且从api响应中获取数组,并且我将在搜索数组中传递,让我展示我的代码

var news = [AnyObject]()
var searchArray = [String]()
 func calSearchAPI(){
  let URL = "http://velanivasaniparivar.org/new_member_search_list.php"
      Alamofire.request(URL, method: .get).responseJSON
            {
                response in

                print(response)
                let result = response.result
                if let dict = result.value as? Dictionary<String,AnyObject>{
                    if let categorylist = dict["operator_list"]{
                        self.news = categorylist as! [AnyObject]
                        print(self.news)
                    }
                }
        }
    }

该新闻数组的值我将通过如下所示的搜索字段方法传递给搜索数组

  func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
        searchArray = news.filter({$0.prefix(searchText.count ) == searchText})
        tblSearchView.reloadData()
    }

但是我遇到错误,就像上面我会告诉你的那样,我认为这是由于数组类型AnyObject引起的,但是与其他类型一样,我却崩溃了,所以请告诉我数组或任何其他方法的正确类型

回复

SUCCESS: {
    "operator_list" =     (
                {
            "A_ADDRESS" = "";
            "A_BLOOD_GROUP" = 1;
            "A_CURRENT_ACTIVITY" = 1;
            "A_DOB" = "{\"D\":\"24\",\"M\":\"October\",\"Y\":\"1954\"}";
            "A_EMAIL" = "";
            "A_FAMILY_ID" = 000001;
            "A_FATHER_NAME" = DHANJI;
            "A_FULLNAME" = MANSUKH;
            "A_MERITAL_STATUS" = 2;
            "A_N_city" = Madanpura;
            "A_PHONE" = ""
            "A_SURNAME" = 2;
            age = "";
            city = Mumbai;
            education = "<null>";
            state = Maharashtra;
            "sur_name" = VELANI;
        }
);
}

0 个答案:

没有答案