[Solved] Parsing JSON in Swfit 3.0 Cast NSArray to NSDictionary Error

You can use this : Since the data in items is array of dictionaries and link is not in internal array it is main dictionary so you can easily get this by passing link in as key. let link = “http://www.flickr.com/services/feeds/photos_public.gne?tags=swimming&format=json&nojsoncallback=1” let urlString = link let url = URL(string: urlString) URLSession.shared.dataTask(with:url!) { (data, response, error) … Read more

[Solved] How to send data to the server(api) using swift

you can send data to server by using Alamofire API. It’s documention and implemention all the stuff are mentioned in the following link. https://github.com/Alamofire/Alamofire Just install it using Pods and it’s very easy to implement. create Network Class and create following function inside it. func get_Request(currentView : UIViewController,action : NSString,completionHandler: (NSDictionary -> Void)) { print(“Url==>>>”,mainURl … Read more

[Solved] Why is this out of index?

Not sure what this is: var mainController = ViewController() var movie = ViewController().self.movieArray[0] Regardless, ViewController() instantiates a new object of that class. At that point, it’s very likely movieArray has never been initialized and has no objects in it. 5 solved Why is this out of index?

[Solved] How to change text color in tableView section in swift

override func tableView(tableView: UITableView!, viewForHeaderInSection section: Int) -> UIView! { var customView:UIView? customView.frame = // set frame according to tableview width and header height customView.backgroundColor = UIColor.greenColor() return customView } Hope this will help you. solved How to change text color in tableView section in swift

[Solved] Add 1 Day to a Date [closed]

The most reliable way to get the next occurrence of a time is nextDate(after:matching:matchingPolicy: of Calendar because it considers also daylight saving changes. assuming datePicker is the NSDatePicker instance: let date = datePicker.date let calendar = Calendar.current // get hour and minute components of the given date let components = calendar.dateComponents([.hour, .minute], from: date) // … Read more

[Solved] While decoding json from webservice, it shows an error: Could not cast value of type ‘__NSArrayM’ (0x10b84bdb0) to ‘NSDictionary’ (0x10b84c288)

Try this var desriptionArray = [String]() for dataValues in responseObject[“result”] as! [[String: AnyObject]] { let name = dataValues [“description”] as! String desriptionArray .append(name) } OR for (index , element) in (responseObject[“result”] as! [Any]).enumerated() { let nameDict = element as! [String : AnyObject] let strDecription = nameDict[“description”] as! String desriptionArray .insert(strDecription, at: index) } solved While … Read more

[Solved] Textfield values set to empty when coming back from previous view controller [closed]

When you push back to the origin viewController, It’s better to replace using “push” Segue by “popViewController” method . It’s also good using data consistent strategy. And the reason: You should consider the viewController’s lifecycle. When you push back to the origin viewController, using “push” Segue makes the origin viewController’s “viewDidLoad” method is called again. … Read more

[Solved] How to browse the document file in iOS [closed]

Two things you can consider: 1. If you have to give permission for sharing document directory in your .plist. Then traverse through file app. 2. Or you have to use UIDocumentBrowserViewController and show list of file and directory. Please check this link : https://developer.apple.com/documentation/uikit/uidocumentbrowserviewcontroller 1 solved How to browse the document file in iOS [closed]

[Solved] How to parse JSON values using Swift 4?

Your code cannot work. According to the given JSON the root object is an array [[String: Any]] and there is no key result at all. let json = “”” [{“id”:1,”class”:”A”,”Place”:{“city”:”sando”,”state”:”CA”}},{“id”:1,”class”:”B”,”Place”:{“city”:”jambs”,”state”:”KA”}}] “”” let data = Data(json.utf8) do { if let json = try JSONSerialization.jsonObject(with: data) as? [[String: Any]] { for item in json { if let … Read more

[Solved] non-void return value in void function table view

Welcome to SO. You are using a function, findObjectsInBackground, that takes a completion closure. The completion closure is another function inside your cellForRowAt function. That function holds onto (captures) the completion closure you pass in and doesn’t call it until the background call is complete. The block you pass in does not return a value. … Read more

[Solved] How To get and convert last character of string into Int in Swift 3?

Simply convert that last character to String and then String to Int. if let last = str.characters.last, let value = Int(String(last)) { print(value) } Edit: If you are having a number like cart10,cart11,…cart100… then to get the number after cart try this way. let str = “cart15” let cartNumber = str.characters.flatMap({Int(String($0))}).reduce(0, {10 * $0 + … Read more

[Solved] check the value of dictionary in array in swift [closed]

Imagine you downloaded some data from the server. You will convert the data into a dictionary using let arrayOfDictionaries = try! NSJSONSerialization.JSONObjectWithData( data, options: .AllowFragments ) var techNames : [String] = [] var adminNames : [String] = [] Then you can iterate doing for dictionary in arrayOfDictionaries { if dictionary[“department”] == “Technology” { // Add … Read more

[Solved] I cant display 3 cell in CollectionView [closed]

UICollectionViewDelegateFlowLayout func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath:NSIndexPath)->UICollectionViewCell { let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: “formCell”, for: indexPath) return cell } For number of item func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 3 } For Get 3 cell in one row func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let … Read more