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.
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 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 8 years ago.
Improve this question
I am following this tutorial: http://jamesonquave.com/blog/developing-ios-apps-using-swift-part-3-best-practices/#comment-12898
I am getting an error “fatal error: unexpectedly found nil while unwrapping an Optional value”.
func didRecieveAPIResults(results: NSDictionary) {
var resultsArr: NSArray = results["results"] as NSArray
dispatch_async(dispatch_get_main_queue(),{
self.tableData = resultsArr
self.appsTableView!.reloadData() // Thread 1: EXC_BAD_INSTRUCTION
})
}
Here is the code from my github: https://github.com/a9austin/JamesHelloWorldTutorial/tree/master/Part1HelloWorld
Thanks for all the help!
The reason for the error is your project does not have an appsTableView in the storyboard. As a result it is not connected to the IBOutlet as shown in the tutorial in Part 2:
http://jamesonquave.com/tutImg/ConnectTableView.png
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 concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
how can I add an object in an array by clicking a button
I use this methode :
- (void)insertNewObject:(id)sender
{
[orderListe addObject:[[DataOrder alloc]initWithName:#"Michael" price:18 taille:#"junior" supplement:#"boeuf"]];
}
When I do that my application crash and say :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DataOrder initWithName:]: unrecognized selector sent to instance 0x8aa4fa0'
What can i do to simply add an object to an array ?
Thank you
The error your getting has to do with the DataOrder object. During it's initialization it ran into an error. You're sending it some value it isn't expecting.
Perhaps try and separate the line where you alloc the Data Order object and try to add it to the array?
DataOrder *do = [[DataOrder alloc] initWithName....];
[orderListe addObject: do];
this will let you see where you messed up?
Of course that you can add an object to an array. The exception is thrown because the method initWithName:price: ... is not implemented in the DataOrder class.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
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
Improve this question
I have a UIButton which when pressed passes an integer to a simple method I have set up. However I keep on getting this error:
Implicit conversion of 'int' to 'id' is disallowed with ARC
Here is my code:
[self performSelector:#selector(show:) withObject:prev_image afterDelay:2.0];
The reason I'm not just doing [self show:prev_image] is because I want a delay before the method is called.
Thanks for your time, Dan.
You have two choices:
Change the show: method to take an NSNumber and then wrap prev_image in an NSNumber or
Use dispatch_after.
Code:
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self show:prev_image];
});
prev_image is an int where an 'object' must be passed into the performSelector method.
I would advise that you do this:
[self performSelector:#selector(show:) withObject:#(prev_image) afterDelay:2.0f];
I would also recommend you change prev_image to prevImage whilst programming in Objective-C simply for style.
Using dispatch_after is not necessary here and you almost certainly want to stay as high level as possible when tackling problems in iOS development.
I apologise for being unclear.
You will also want to change the method signature and implementation of show:
- (void)show:(NSNumber *)number
{
NSInteger integerNumber = [number integerValue];
}
One solution is to use [NSNumber numberWithInt:prev_image] instead of prev_image. Also you'll need to change the show: method to to take an NSNumber instead of an int.