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);
}
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 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
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 6 years ago.
Improve this question
Is there a way to call metatable methods inside the metatable itself? For example
local t = {}
local mt = {
__index = {
dog = function() print("bark") end,
sound = function() t:dog() end
}
}
setmetatable(t,mt)
t:Sound()
raises this error:
attempt to call method 'Sound' (a nil value)
because you don't have Sound. Only sound.
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
I have a location app that already successfully asks the user to enable location services, and then can show them their coordinates on a button press as well. So I decided to play around with everything that is available in the CLLocationManager reference provided by xcode.
I decided to setup a bool method called "locationServicesEnabled". It returns a value of YES(1) or NO(0). I declared the method and then went to implement it. I am trying to have NSLog print the bool result out to the console when you open the app.
Here is how I declared the BOOL method in my ViewController.m file:
#interface ViewController () <CLLocationManagerDelegate>
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
+ (BOOL)locationServicesEnabled;
#end
And here is how I implemented the BOOL method in ViewController.m:
+ (BOOL)locationServicesEnabled{
[self locationServicesEnabled];
NSLog(#"%hhd", self.locationServicesEnabled);
return 0;
}
Why do you want to create an extra method? You could minimize the risk of errors by using already available ones: NSLog(#"Location services enabled: %d",[CLLocationManager locationServicesEnabled]);
I think your issue might be the fact that you are calling your function inside its self:
+ (BOOL)locationServicesEnabled
{
[self locationServicesEnabled]; <- should this be here
NSLog(#"%hhd", self.locationServicesEnabled);
return 0;
}
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];
}