I'm building a quiz system and i'm not sure how to structure it on the database side.Let's say the quiz system is for trees species. User will be presented a tree picture (an entry), and will have to select the correct species among a list of 6 (5 random, 1 correct). There are 250 species in the quiz.The two main problems I need to solve:1) User should never see again the same tree entry.2) Owner of a tree entry, must be able to see stats of all the votes on his entry: so he will see number of votes, per tree species, entered by other users on his entry. Because users will make mistakes on votes, owner of entry will see stats of those mistakes and which incorrect species his entry was mistaken for.An easy way to do it, would be to create several tables:Users tableTrees table: With foreign key to User table. This is entries users will have to vote on. One user can create one entry.Votes tables: With foreign key to both user table and tree table. This table will hold each and every vote, including tree species name selected by the user on that vote.So to solve my problem:1) Prevent user to see same entry again: Before fetching "Trees" to present new trees to vote on, run a first query to get all "Votes" for that user to exclude "Trees" the user has already voted on.2) See stats of votes on own entry: Fetch all votes pointing to own entry, then compute stats by tree species selected.This approach is straightforward, but what bothers me is having to create an entry for each and every vote. There can be lots of it. I'm inexperienced with db design, so not sure if this could be a problem or not.Would this alternative way be better:1) To keep track of already voted entries: On a single record (per user), hold in a single field, ALL voted ids, so instead of running a query to prefetch each votes entries, simply get them from a single field. Not sure if this is doable, and what is the limit size of a single field that could potentially hold thousands of votes which are in fact ids of entries voted on.2) So owner of an entry can view that entry statistics: On EACH tree entry, create 250 columns, one per tree species, and increment an INT on each depending on what is voted on. So to get stats of each entry, it would only be a matter of fetching one single record and do the computation client side.What would be the best approach? Is there one that should be avoided?
Post
Replies
Boosts
Views
Activity
class One {
func sayOne() {
print("from inside One")
}
class Second {
func saySecond() {
print("from inside second")
}
}
}
One.Second().saySecond()
Why can I access Second class without instantiating One() with parenthesis, when I can't access member function and variables without instantiation with ()?
This code is invalid:
func name1() {
func nest1() - Int {
print("nest1")
return 3
}
func nest1() - String {
print("nest2")
return "nest1"
}
}
both nest1 function can't coexist.
But they have a different signature: one is returning an int and the other a string.
Aren't functions with different signatures, supposed to be able to coexist?
Hi,
my native iOS app requires user to be logged in to use its features.
I implemented a clean and neat sign it with apple.
Is it even worth bothering implementing other signs in, like fb, or google?
This message is for people using apple sign in as well as other sign in methods, if you could share your rough % of sign in distribution.
Thanks,
Ald
Hi here is the code:
let button = self.votingButtonsContainer[0]
let layer = button.layer
let rotationAngle: CGFloat = 49
var rotationAndPerspectiveTransform = CATransform3DIdentity
rotationAndPerspectiveTransform.m34 = 1.0 / -500
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, rotationAngle * .pi / 180.0, 0.0, 1.0, 0.0)
layer.transform = rotationAndPerspectiveTransform
This code correctly rotate in 3D my "button" in this case by 49 degrees (rotationAngle).
Problem is that this is not animated.
How to make this code animate the rotation, instead of simply displaying the result?
Hi,
down there you will find an implementation of the coreML/squeeze net that prints first prediction and confidence level.
Problem is that its prediction are not general enough: if I send it a dog, it will try to guess the dog breed, instead of general categorization of "Dog" or even "Animal".
Is there anyway to ask the model to return broader category?
static func analyzeImageMl(image: UIImage) {
if let imageToParse = image.cgImage {
do {
let model = try SqueezeNet(configuration: MLModelConfiguration())
let mlModel = model.model
do {
let visionModel = try VNCoreMLModel(for: mlModel)
let request = VNCoreMLRequest(model: visionModel) { (response, error) in
if let e = error {
print("Error is: \(e.localizedDescription)")
}
if let r = response.results as? [VNClassificationObservation] {
if let f = r.first {
let id = f.identifier
let confidenceToPercent = f.confidence * 100
let confidenceString = String(format: "%.2f", confidenceToPercent)
print("I think this object is: \(id)\n with a confidence of: \(confidenceString)%")
}
}
}
let handler = VNImageRequestHandler(cgImage: imageToParse, options: [:])
try handler.perform([request])
} catch {
print(error.localizedDescription)
}
} catch {
print(error.localizedDescription)
}
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
for percent in 1...10 {
print(percent)
self.accuracyLabel.text = "\(percent)" + "%"
sleep(UInt32(0.9))
}
}
@IBOutlet weak var accuracyLabel: UILabel!
Hi,
I have 2 problems with this code:
1) sleep(UInt32(1.0)) correctly prints 'percent' every 1 second.
But as soon as I go under 1.0, such as sleep(UInt32(0.9)), the print don't happen every 0.9 seconds, but instantly. Why is that?
2) @IBOutlet weak var accuracyLabel: UILabel! text is not updated on each iteration, but only after entire loop has completed. This is not what I would have expected, I would have expected update on each iteration, why is it not the case?
regards,
Brak
Hi,
I need to move the controller up so fields are not hidden by keyboard.
So I use textfield and textview delegate methods to achieve this.
Here is the code, but it is repetitive.
Is there any way to make it less repetitive?
func textFieldDidBeginEditing(_ textField: UITextField) {
self.view.setNeedsLayout()
UIView.animate(withDuration: 0.2, animations: {
self.view.center.y -= 150
}, completion: { finished in
})
}
func textFieldDidEndEditing(_ textField: UITextField) {
self.view.setNeedsLayout()
UIView.animate(withDuration: 0.2, animations: {
self.view.center.y += 150
}, completion: { finished in
})
}
func textViewDidBeginEditing(_ textField: UITextView) {
self.view.setNeedsLayout()
UIView.animate(withDuration: 0.2, animations: {
self.view.center.y -= 150
}, completion: { finished in
})
}
func textViewDidEndEditing(_ textField: UITextView) {
self.view.setNeedsLayout()
UIView.animate(withDuration: 0.2, animations: {
self.view.center.y += 150
}, completion: { finished in
})
}
Hi,
on this page:
https://developer.apple.com/documentation/vision/vnrecognizeanimalsrequest/3366120-knownanimalidentifiers
it is stated that this function: "Returns a list of animal identifiers the recognition algorithm supports for the specified revision."
How can i build a test code in playground to get that list of animals identifier?
What is the general methodology to run such functions from the documentation?
Hello,
here is a particular localization scenario i'm not sure how to handle with default localization feature:
App base language is english, translation is french.
1) On app load, swift will pick up 6 random items from a strings array of 100 items.
2) It will display each of those 6 strings on 6 user interface buttons.
3) User will tap on a button: string value is sent back into app.
Here is the problem:
4) App will do processing with this value. Problem is that all internal processing from that values that went out from the array on user interface then back in app, is all done with english values. In particular that user choice is saved in external database, and I can't have saved in database localized versions: all internal processing on array values in english.
How best to handle this situation?
Is it possible from a localized french VALUE, to get corresponding VALUE in base language?
If yes how?
Or should I build my own thing for those cases when random values goes out on UI, then back in app... like an array of tuples containing translated items?
Hi,
do you have any advice for quickly building an iOS App's website?
It will be very simple: frontpage, privacy, contact page....
I'm ok with pure html template, php, or wordpress templates, or any other smart way of doing this.
Thanks,
Aldar
Hi,
here is a curious behavior hapening to my app.
Here is the use case.
App base lang is english.
Other translation is french
On a view controller, I have this: self.introTextView.text = "DogProfileEditionVC-IntroTextView".localize()
On corresponding language files I have these:
"DogProfileEditionVC-IntroTextView" = "french text";
"DogProfileEditionVC-IntroTextView" = "english text";
Use case on a freshly opened or built app: Load viewcontroller. Text is correctly displayed in language.
dismiss view controller.
Open view controller again: text loaded is neither from the translation file, but from the storyboard.
So on first loading after app was closed, opened, or built, the view controller shows correct text. On subsequent display, it ignores translation files and only load text from storyboard.
This happens only one one view controller, and 3 texts. This doesn't happen on some text on the same VC.
Why this strange behavior? Why does it localize only on first presentation of the view controller, and not on subsequent opening unless I close app in between?
(i tried to reinstall app, clean build folder)
Here are the string extensions used to localize:
// Add method to Strings for easily triggering the localization process.
extension String {
func localize() - String {
return NSLocalizedString(
self,
tableName: "Localizable",
bundle: .main,
value: self,
comment: self)
}
public func localize(with arguments: [CVarArg]) - String {
return String(format: self.localize(), locale: nil, arguments: arguments)
}
}
Hi,
tabBarItem.title = "LevelsVC-TabBarItem".localize()
with tabBarItem.title i'm able to localize title when it is in viewDidLoad or viewWillappear but the localization will only happen when the tab becomes actives, otherwise it will show default value.
How could I localize, programmatically, the item title without the need to make it active?
Hi,
I need the fastest, earliest programmatic transition possible from one vc to another. So I need to have
performSegue(withIdentifier: "fromEntryToVoting", sender: nil)
performed as fast as possible so the transition happens as quickly as possible. But the vc containing this method should remain in the stack.
It won't work from ViewDidLoad but will work from viewDidAppear.
Is there an earlier method I can use to put my performeSegue so it will be performed asap?
Hi,
here is a class for a UIKIT button.
Some of those settings work, usch as cornerRadius: it does affect the button display, but some doesn't.
For example, the size from
self.titleLabel?.font = UIFont(name: "Avenir Next Condensed Regular", size: 3)
has no effect at all on the text of the font inside the buttons.
Why is that? And how can I effectively alter the size of text from this subclass?
class VotingButtonStyle: UIButton {
override func draw(_ rect: CGRect) {
super.draw(rect)
self.clipsToBounds = true
self.titleLabel?.font = UIFont(name: "Avenir Next Condensed Regular", size: 3)
self.setTitleColor(.black, for: .normal)
self.titleLabel?.numberOfLines = 3
self.layer.cornerRadius = 8
}
}