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 7 years ago.
Improve this question
I want a function to be called at random times while the user is playing. For example after 2 seconds passed a function is called and then after another 6 seconds it is called again. How do I do that?
This is not working
func time() {
randomNumber = CGFloat((drand48())
timer = NSTimer.scheduledTimerWithTimeInterval(randomNumber, traget: self, selector: "startTimer", userInfo: nil, repeats: true)
Xcode is not liking it and I donot know why
Welcome to SO. This is not a site where you get other people to write your code for you. It's a site to ask for help with code you write yourself.
You want to use arc4random_uniform() to create a random number, and then scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: to fire your timer at a random time in the future.
Try that, and if you have problems, update your question with the code you're trying and tell us what happens with it.
Edit:
Here's a suggestion: log a few values of randomNumber. Are they small values? Those are a delay in seconds. If you are getting values of 1000, 1,000,000, or greater, it's going to take a while for your timer to fire.
Related
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 1 year ago.
Improve this question
Basically, I have two points, A and B that are 10 miles apart if you drive. I draw a route using driving directions between them using MapKit.
I want to find point C's latitude and longitude, which is at the point on the route 2 miles from point A. This could also work based on a percentage(ex: 20% of the route is completed between point A and B).
Hopefully, this image can explain better then I can.
Does anyone have any idea on how to do this using Swift and MapKit?
Thanks!
You may want to check out the MKRoute response you receive from the MKDirections.
An MKRoute object defines the geometry for the route—that is, it contains line segments associated with specific map coordinates.
You will find the documentation for MKRoute here:
https://developer.apple.com/documentation/mapkit/mkroute
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 2 years ago.
Improve this question
I need to measure performance of different swift libraries without writing UI on iPhone. There are many examples of Swift/UI examples that are normally, multi-threaded in nature. So what I want to measure is raw performance without gui overhead, if possible. And the output can we printed into the Xcode 11 console window in debugger, for example. Could you please kindly point me where I could find such sample code ? I would greatly appreciate the help.
This is an example of how to measure the time of a sum of numbers
let numbersArray = [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6]
func showBenchmarkTime(title:String, operation:()->()) {
let startTime = CFAbsoluteTimeGetCurrent()
operation()
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime
print("Time elapsed for \(title): \(timeElapsed) s.")
}
showBenchmarkTime(title: "sum an array of numbers") {
print(numbersArray.reduce(0, +))
}
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 3 years ago.
Improve this question
ROM is implemented by case statement to store fixed values in it and read them whenever we need.
But how can I read two values at the same clock cycle ??
It is always useful to show at least part of your code. I assume you have something like this:
case (adrs)
8'h00 : dout <= 8h01;
8'h01 : dout <= 8h03;
8'h02 : dout <= 8h07;
The only solution is to make two identical case statements but it is easier to instance the same ROM twice.
Alternative is to make a memory and initialise it.
reg [7:0] mem [0:255];
... // initialise memory e.g
... // using initial with for loop and case statement
always #(posedge clk)
begin
dout1< = mem[adrs1];
dout2< = mem[adrs2];
end
I assume this is for an FPGA so look at the vendor manual how to make a pre-loaded RAM. (Which is on fact a ROM as long as you don't write to it)
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
how can i make a counter to be used in addressing issues. (sample output: Issue 001). I need to save the current value of the counter(001) in the device so that when there is another issue to be sent by the app i will increment the current value of the counter.
Don't know where to start.
thanks in advance.
You can use the NSUserDefaults
get and store the value
NSInteger count = [[[NSUserDefaults standardUserDefaults] valueForKey:#"count"] integerValue];
count++;
[[NSUserDefaults standardUserDefaults]setValue:[NSNumber numberWithInteger:count] forKey:#"count"];
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 wonder How Make the players waiting؟ like candy crush When the player loses all points of Health He must wait some time
How i can do this?
Thanks
Create a date object when the player loses
NSDate *stopTime = [NSDate dateWithTimeIntervalSinceNow:0];
and store that date in NSUserDefaults. To check if the user has waited long enough, read the date from NSUserDefaults, and compute the delta between the stop time and the current time. For example, if the user needs to wait 15 minutes, then
NSTimeInterval delta = [stopTime timeIntervalSinceNow];
delta = -delta;
if ( delta > 15 * 60 )
// OK to play
else
// still waiting