I want to generate tableview form with JSON data [closed] - ios

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a JSON data in my local file, I want to replicate same in my form.
JSON data tell us info like, which field is required, which is dropdown, placeholder and more info.
Almost I achieved my goal, but only the thing is keyboard taking double taps to show when I am switching the text fields.
I was stuck on this issue. Can anyone help me?
I cant explain the issue with the small code, that's why adding complete source code, so please excuse.
here I am adding my source code link,
https://drive.google.com/file/d/12vhrz6CgDSuma6ViYOsGkCIb9SE6fSbR/view

Try using :
func updateModel(text: String, indexPath: IndexPath) {
var item = self.viewModel.get(at: indexPath)
item.value = text
item.indexPath = indexPath
self.viewModel.formModel[indexPath.section].items![indexPath.row] = item
self.tableForm?.reloadRows(at: [indexPath], with: .automatic)
}
Also, avoid retain cycle using weak self :
self.viewModel.fetchFormData(fileName: "fields") { [weak self] (data, error) in
if (error?.isEmpty)! {
self?.tableForm?.reloadData()
}
}
Otherwise ViewController & ViewModelForm will be kept in memory forever

In updateModel function you need to replace
self.tableView.reloadData()
with
self.tableForm?.reloadRows(at: [indexPath], with: .automatic)
So the basic rule says if you only wish to reload a single row in table view use reloadRows instead of reloading the complete table view.

Related

List view really slow and laggy [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm loading around 500 rows of data into a List. It was okay when I had 10 rows but now that I have 500 it's extremely slow. Is there anything I can do to help it's performance?
List {
SegmentedControl(selection: $feedType) {
ForEach(FeedType.allCases.identified(by: \.self)) { type in
Text(type.rawValue)
}
}
ForEach(store.stories) { story in
NavigationButton(destination: Text("")) {
StoryRow(story: story)
}
}
}

Google Maps URL Schema for multi stops [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I would like to open Google Maps app on iOS using the url scheme for showing directions with multiple stops.
The web url for testing is:
https://google.com/maps/dir//49.54643774,22.28223445/49.54679476,22.28170513/49.54726735,22.28154318/49.54760869,22.28156607/49.54820312,22.2815506/49.54856556,22.28146425/49.54907329,22.28133231/49.54989807,22.28207924/49.55017454,22.2824851/49.55064392,22.28306989/49.5508548,22.28325003/49.55143275,22.28381447/49.55169439,22.28410868/49.5520271,22.28443534
I tried many configurations of the app scheme using comgooglemaps:// without success.
You can read the Google Maps documentation for opening the app.
To simplify it, this is the format you need to follow:
comgooglemaps://?saddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA+94043&daddr=Google+Inc,+345+Spear+Street,+San+Francisco,+CA&center=37.422185,-122.083898&zoom=10
in swift you would do something like this, take note of the callback option, you can choose to not have it if you don't want to return to your app:
let testURL = URL(string: "comgooglemaps-x-callback://")!
if UIApplication.shared.canOpenURL(testURL) {
let directionsRequest = "comgooglemaps-x-callback://" +
"?daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York" +
"&x-success=sourceapp://?resume=true&x-source=AirApp"
let directionsURL = URL(string: directionsRequest)!
UIApplication.shared.openURL(directionsURL)
} else {
NSLog("Can't use comgooglemaps-x-callback:// on this device.")
}
Edit: To use coordinates, use it this way:
comgooglemaps://?saddr=52.3668563,4.8890813&daddr=52.357516,4.902319&zoom=10
Edit 2: For for more points on the map append coordinate using +to:Latitude,Longtitude to the daddr parameter
comgooglemaps://?saddr=52.3668563,4.8890813&daddr=52.357516,4.902319+to:52.357786,4.891913&zoom=10

Programmatically remove contact from adress book on specific time in swift [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am trying to programmatically remove contacts from address book on specific time. Is it even possible in Swift and do Apple allow it?. I'm already familiar with CNContactStorebecause I have got working adding contacts into phonebook. Granted access into Contacts etc.. But I do not know how to programmatically delete contacts from addressbook(forever) on specific time.
Any help is appreciated!
REFERENCE:
http://www.ios-blog.co.uk/tutorials/swift/contacts-framework-p2/
EXPLANATION (FROM THE LINK):
Delete Contact
"The iOS contacts framework gives us the function deleteContact(:) to help us delete contacts. Hopefully you’ve understood this tutorial enough so far to proceed as I’m only going to outline the process and let you have a try. Just like we have throughout this tutorial we are going to instantiate an object of type CNSaveRequest, Issue the deleteContact(:) function that I just mentioned and pass the mutable contact to it. Then, Like when we created contacts or updated contacts we are going to use the executeSaveRequest(_:).
Please note that Delete means Delete! Contacts that are deleted can not be obtained again. This shouldn’t matter too much on the simulator but you do need to make sure that you have safety protocols in place so that you don’t delete a users contacts.
So, Did you manage to get the delete working? Ok, Fine, I will post the full code so you can see."
SOLUTION (FROM THE LINK):
let predicate = CNContact.predicateForContactsMatchingName("John")
let toFetch = [CNContactEmailAddressesKey]
do{
let contacts = try store.unifiedContactsMatchingPredicate(predicate,keysToFetch: toFetch)
guard contacts.count > 0 else{
print("No contacts found")
return
}
guard let contact = contacts.first else{
return
}
let req = CNSaveRequest()
let mutableContact = contact.mutableCopy() as! CNMutableContact
req.deleteContact(mutableContact)
do{
try store.executeSaveRequest(req)
print("Success, You deleted the user")
} catch let e{
print("Error = \(e)")
}
} catch let err{
print(err)
}

Whats the best way to parse JSON format in iOS Swift? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I have a project that polls a URL that returns a JSON format values. Any recommendations of whats the best way to parse the result for my iOS app?
First of all there is no such thing as best way. If there was a best way, you will probably heard it or find it among top google hits.
You can make do-it-yourself with NSJSONSerialization. This what Apple provides, and it is merely the fastest and the hardest to use. It's not even that 'hard', it just get's complicated when JSON has manny sub-levels.
What I can recommend you is SwiftyJSON. It had minor(barely noticable in most apps) overhead but it's much more easier to use in Swift. A great example is found on raywenderlich site.
You can also simply parse
var data = NSData(contentsOfURL: NSURL(string: "http://api.androidhive.info/contacts/")!)
var parcedData : NSMutableDictionary = NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments, error: nil) as! NSMutableDictionary
print(parceData)
There are many other ways to do it.
You can use Alamofire with SwiftyJSON
Snippet With Alamofire and SwiftyJSON
Alamofire.request(.GET, url, parameters: parameters)
.responseJSON { (req, res, json, error) in
if(error != nil) {
NSLog("Error: \(error)")
println(req)
println(res)
}
else {
NSLog("Success: \(url)")
var json = JSON(json!)
}
}

Swift: Create table of results from SwiftyJson Results [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have been playing around with Swift as I'm new to iOS Development and really enjoying getting to know the language. Recently I have started to look at installing third party plugins etc and I found one called SwiftyJson (https://github.com/SwiftyJSON/SwiftyJSON) I have managed to get it to work using this script:
request(.GET, url, parameters: parameters)
.responseJSON { (req, res, json, error) in
if(error != nil) {
NSLog("Error: \(error)")
println(req)
println(res)
}
else {
NSLog("Success: \(url)")
var json = JSON(json!)
println(json)
}
}
I would like to know two things: 1) Is it possible to get the list of results from the JSON provided into a UITableView like so:
Item 1
----------------------------
Item 2
----------------------------
Etc.. and 2) How would I do that?
Edit: Json
Sorry about image - I couldn't copy it because of a stupid chrome extension I have:
Yes it is possible, though you aren't really using the important features of SwiftyJSON in this code sample. The most straightforward way would be to create the tableview the same as you would for anything, likely using an array as your datasource. Once you've received your JSON you still need to parse it and create the objects for your array. Perhaps if you included a snippet of the JSON, it would be easier to help.

Resources