methods

Does iPhone SDK Objective C support functions inside of functions?

好久不见. 提交于 2019-12-12 08:09:17
问题 I know that javascript, for example supports functions inside of functions, like so: function doSomething(){ function doAnothingThing(){ //this function is redefined every time doSomething() is called and only exists inside doSomething() } //you can also stick it inside of conditions if(yes){ function doSomethingElse(){ //this function only exists if yes is true } } } Does objective-c support this? Theoretical example: -(void) doSomething:(id) sender{ -(void) respondToEvent: (id) sender{ /

Function/Method Overloading C++: Data type confusion?

笑着哭i 提交于 2019-12-12 07:49:33
问题 I'm having some trouble overloading methods in C++. As an example of the problem, I have a class with a number of methods being overloaded, and each method having one parameter with a different data type. My question: is there a particular order in the class these methods should appear in, to make sure the correct method is called depending on its parameters data type? class SomeClass{ public: ... void Method(bool paramater); void Method(std::string paramater); void Method(uint64_t paramater)

Python method accessor creates new objects on each access?

血红的双手。 提交于 2019-12-12 07:49:25
问题 When investigating for another question, I found the following: >>> class A: ... def m(self): return 42 ... >>> a = A() This was expected: >>> A.m == A.m True >>> a.m == a.m True But this I did not expect: >>> a.m is a.m False And especially not this: >>> A.m is A.m False Python seems to create new objects for each method access. Why am I seeing this behavior? I.e. what is the reason why it can't reuse one object per class and one per instance? 回答1: Yes, Python creates new method objects for

unbound method with instance as first argument got string but requires something else

和自甴很熟 提交于 2019-12-12 07:47:55
问题 #Maps.py class Maps(object): def __init__(self): self.animals = [] self.currently_occupied = {} def add_animal(self, name): self.animals.append(name) self.currently_occupied = {robot:[0, 0]} #animal.py class Animal(object): def __init__(self, name): import maps maps.add_animal(rbt) self.name = name #Tproject.py from Animal import Animal Fred = Animal("Fred") gives me this an error that looks like this TypeError: unbound method add_animal() must be called with Maps instance as first argument

Databinding to a method in WPF

血红的双手。 提交于 2019-12-12 07:45:25
问题 I am having trouble databinding a TextBox.Text property to a object's method. The idea is allowing the user to write in a TextBox a file name and then have a TextBlock output that file's extension. class GetFileInfo { public string GetFileExtension(string fileName) { return Path.GetExtension(fileName); } } Here is my XAML: <Window.Resources> <ObjectDataProvider x:Key="getFileInfo" MethodName="GetFileExtension" ObjectType="{x:Type local:GetFileInfo}"> <ObjectDataProvider.MethodParameters> <sys

Variable length parameters in Objective-C

若如初见. 提交于 2019-12-12 07:23:18
问题 How can i make a class method with variable length parameters, in Objective-C? For example, a method like -arrayWithObjects: NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil]; 回答1: What you need is a variadic function. These functions take a flexible number of arguments, like NSLog , [NSArray arrayWithObjects:...] , etc. See this tutorial: http://www.numbergrinder.com/node/35 Copied from my answer here: Obj-C, trying to write an alternative to NSLog, but I want my function to

How to validate a string is JSON or not in Java?

瘦欲@ 提交于 2019-12-12 07:05:08
问题 I've already said, my question is different...question is already asked here, but i want a predefined method in java which checksgiven string is json format or not. if there is no predefined method then at least tell a code which checks JSON Format or not, without using try catch block.. Thanks in advance... 回答1: Use JSONObject's constructor from a String try { JSONObject o = new JSONObject(yourString); } catch (JSONException e) { LOGGER.error("No valid json"); } 回答2: public boolean

Java: method not working

余生长醉 提交于 2019-12-12 07:03:55
问题 I am creating a program that simulates some people catching fish in a lake, I already created classes for Fish and Pond and I was working on the Fisher class and a method is not working and I'll show the code (I'm new to programming so I'm not sure if I am providing enough information) public class Fisher { public static int LIMIT = 3; private String name; private Fish[] fishCaught = new Fish[LIMIT]; private int numFishCaught; private int keepSize; public Fisher(String name, Fish[] fishCaught

The formula that I have in my code which is causing the error is the formula that was given for the assignment

让人想犯罪 __ 提交于 2019-12-12 06:58:27
问题 //The error message I'm getting is saying "cannot find symbol- method second(double) but I feel as though I have identified everything already. (I'm clearly wrong). I think there is a problem with the formula as well but that is the code I was given for the formula. Any help would be greatly appreciated. import java.util.GregorianCalendar; import javax.swing.JComponent; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.*;//import * Class public class ClockComponent

Python: How to call class method from imported module? “Self” argument issue

陌路散爱 提交于 2019-12-12 06:57:52
问题 I have 2 files. I know how to call a function, but cant understand how properly to call a method from imported module which has "self" as the 1st argument. I got this error: TypeError: prepare() missing 1 required positional argument: 'url' cinemas.py import requests from lxml.html import fromstring class cinemas_info(): def __init__(self, url): self.basic_cinemas_info(url) def prepare(self, url): url = requests.get(url) tree = fromstring(url.text) tree.make_links_absolute(url.url) return