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
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
parallax.update(currentTime)
}
How can i control the update to be done once over a specific period of time
Your code doesn't add much to your question, so I don't really know if this is what you are looking for, but here is some code to call a function every X time (swift 3):
// call MyMethod every 1 second :
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(MyController.myMethod), userInfo: nil, repeats: true)
Please search before you post a question -> answer
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm creating a closure to call from a storyboard outside the framework I'm creating.
However, when trying to implement said closure through the guidance of this SO post, I'm getting the following errors:
1. '_' can only appear in a pattern or on the left side of an assignment
2. Consecutive statements on a line must be separated by ';'
3. Expected expression
Here is the current code inside my swift file:
//Here is where I'm getting the mentioned 3 errors
var sliderChangeforward: (UISlider) -> Void { _ in }
#IBAction func sliderDidChange(_ sender: UISlider){
...
sliderChangeforward(sender)
}
Any help is greatly appreciated.
You omitted the equals sign.
var sliderChangeforward: (UISlider) -> Void = { _ in }
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
How to limit download time in ios?
I need :
if download time from url to ImageView more than 2 second, download from another url.
Set the timeout to a shorter time, 2 seconds:
let request = NSMutableURLRequest()
request.timeoutInterval = 2.0
Timeout reference
If you download images asynchronously, you can use this method (together with if):
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(numberInSeconds * Double(NSEC_PER_SEC)))
dispatch_after(delayTime, dispatch_get_main_queue()) {
print("Delayed job")
}
So if numberInSeconds is 2, the code will execute after 2 seconds.
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
Hi I am new to programming, but I can't seem to get this to work.
When I try to run the method from another method every thing stops
-(void)rotateMmovment {
}
-(void)stickMove {
[self rotateMmovment];
stick.center = CGPointMake(stick.center.x + x, stick.center.y);
}
First you should check either your method is running or not via using NSLog.its does't seems that you are facing problem due to calling method which have empty body
-(void)rotateMmovment {
NSLog(#"My method is running");
}
-(void)stickMove {
[self rotateMmovment];
stick.center = CGPointMake(stick.center.x + x, stick.center.y);
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How do i keep the UILabel updated as the time passes when a post is posted in ios ..like if >its posted just now it should say 0s and as time passes it changes to >1min,2min...1hr,2hr...1day and so in ios
I am new to the ios development
Thanks for any help!
You need to use NSTimer for this purpose if I understand your questions properly.
Doing something on a regular interval is pretty easy in iOS.
In your main code:
[NSTimer scheduledTimerWithTimeInterval: 1.0
target: self
selector: #selector(doSomething:)
userInfo: nil
repeats: YES];
Then add the doSomething method:
- (void)doSomething:(NSTimer *)timer {
NSLog(#"We did it!");
}
First of all you need to keep the date when user posted. You can easily do that by using:
NSDate* postedDate = [NSDate now];
Than if you want to find a seconds left from that time you can use:
NSTimeInterval timeDiff = [[NSDate date] timeIntervalSinceDate:postedDate];
This gives you seconds from posting date - you need to format output.
For keeping label updating itself you should use NSTimer:
[NSTimer scheduledTimerWithTimeInterval: 1.0f
target: self
selector: #selector(updateLabel:)
userInfo: nil
repeats: YES];
Where updateLabel will format "timeDiff" into something human readable like 1minute / day etc...
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 have a method that starts my game (startGame). I call it in viewDidLoad ([self startGame];). The problem is, that the start game method checks to see if an object has moved before it starts the game. The setup I have right now only calls the method once and doesn't check it again which means my game never starts. Any ideas on how I can continue checking the method UNTIL the game starts, and then stop checking it?
Thanks. Happy 2012
there are a few things you can do.. one of the easiest would be to use a NSTimer. so in your viedDidLoad method you could do:
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(checkObjectMoved:) userInfo:NULL repeats:YES]; // check every 1 second
then you'd have:
- (void)checkObjectMoved:(NSTimer *)timer {
if object has NOT moved return;
[timer invalidate];
[self startGame];
}