Achieving a more generic approach to my function in Swift [closed] - ios

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 an array in Swift that holds the number of shifts you've worked for the work week.
I would like to retrieve the first element from this collection that matches on a particular condition (in this case date worked).
Later, however, I may also want to find other things such as your highest earning shift. I might even want to select all items that match a particular clause instead of just one.
Are predicates involved here in doing something like this generically? Would anyone be able to point me in the right direction or share some code examples that could help me achieve this so I don't have to write multiple functions for a specific purpose on an array?
Thanks so much for your help!

The easy answer is simply to use indexOfObjectPassingTest and the correct predicate. This is effective when you want to do a small number of unique searches on a small array, where it's next to useless to abstract each type of search in its own function.
However:
if you have the same search made in multiple places in your code, consider abstracting the code into functions and even its own class
if you have a very large array and if the predicates can be very complex, consider CoreData or another database solution. You'll be better off in the long run.
if you need large result sets, also consider CoreData/databases

Related

Handling the deletion of old database objects [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 2 years ago.
Improve this question
I have a few core data entities in my app.
One entity for example, is a more complicated one and represents a task. Something like 12 fields consisted of the premetive types of String and Int and some relationship to "premetive" core data entities, like an entity that represents an hour in the day and consists of two fields of int.
Are this type of objects can actually effect the device free space in any significant way in the long term of months and years ? Should I routinly delete them ?
All data that your app saves affects the free space on the device. Whether it's significant depends on how much data you're saving. If it's 1 or 2 old instances and the strings are short, nobody will ever notice. If it's 1 or 2 billion old instances or if some strings can be really long, you need to take some action.
In general you should delete any data you won't use any more. Not "routinely", but literally as soon as you're sure you don't need it any more. Not deleting it is sloppy programming that shows lack of care for your users. Nobody expects you to be perfect, of course, but if you don't need the data, you should delete it. And of course, it's OK to cache some data that you don't need right now but that you might download from a web API in the near future.
If you do need the data though, don't delete it. If there's a lot of it, look in to whether some can be moved off of the device to a web service of some kind, but don't delete it.

iOS Generating Random Test Data [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 4 years ago.
Improve this question
For testing, I needed to generate a list of data values randomly and put them into the models for further use. But I found out that there is no library, which could produce such functionality.
The elegant solution I expected to find had to combine such simple things as:
the variety of data;
the variety of methods to reach this data;
the possibility to change the default data set to the custom one.
Since I hadn't found the accurate solution, I decided to create my own library (ref. https://github.com/codeitua/ios-data-factory).
There were implemented all necessary methods for data generation (including random names, cities, addresses, dates etc) and data retrieve. And moreover, it has "swifty" interface, which provides comfortable use in every project.
I hope, it will be helpful for everyone, who faced the same problem as me!

How and where to declare constant that should contain AR object? [closed]

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 8 years ago.
Improve this question
I'm developing app that help people overview results of their training. In different disciplines different calculations. And I need to store discipline in object related to training.
I have to use this values in code to programmaticaly set fields of another objects, calculate results depend on it, and later to compare with it.
For example I have model Discipline and three records with names
Speed on 400 m
Speed on 1 km
Speed on 4 km
So it's some kind of constants and I'm just wondering what is the best practice to declare and access them?
Or may be is there any way to declare predefined objects?
Anytime you have "predefined" objects you should probably look into using an enum, though I don't really know why you would want to do that with an AR model. The whole idea behind an AR model is that it's an interactive object backed by a database that can have its attributes manipulated via CRUD operations.

Core Data or .Plist? [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 9 years ago.
Improve this question
I would like to create an application that stores 3 informations:
the patient's name (string)
the test result (int) and
the date of testing.
In the first UIView, a TableView will show up with a list of patients. By clicking on any cell in the UIView, the list of tests with dates that the patient performed is shown. I'm just starting on Objective-C and have not found the best way to do this. Using Core Data and SQLite? Using a .Plist file? And for arrays? I will create 3 arrays?
My first idea was to create an NSMutableArray of patients and each associate a test, but in this case for a patient to carry out various tests, his name will shown repeated in the list of patients. I couldt find thought how could filter theNSMutableArray` (with predicate?) To display the test data for a single patient in the next screen. Any ideas?
Your question is a bit too generic to answer it properly.
But if you save patient information you should definitely consider encrypting the data.
CoreData sounds a bit overkill if you save a very limited amount of data and you don't want to worry about data management, schemas and migrations.
A PLIST storage sounds like a perfectly reasonable solution.
Regarding your data structure.
You have an array of patients in your first view. When you select a cell to get to the next view, you'll pass the selected patient to the next view.

In solr how do you maximize variability within a page of a result set? [closed]

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 8 years ago.
Improve this question
This is for a product search where we want to show a variety of brands in the search results (24 per page). Ideally we would limit it to each item on the page must have a unique brand id, unless given the page in the result set, that is impossible.
Any ideas on how to accomplish this?
what a great question! There's no simple answer, but you might want to try using the grouping functionality that Solr provides. This would you give you one result per brand id that has matching results. If you don't get enough results from that, you could fall back to the "regular" search results. But I don't know of any way to distribute results evenly throughout your brands, because Solr results are ordered using a scoring mechanism where each result is scored independently. Perhaps you could write a Scorer with some memory that would down-weight subsequent matches from previously-seen brands?

Resources