Objective-C function with default parameters? [duplicate]

There’s no default parameters in ObjC. You can create 2 methods though: -(void)fooWithA:(int)a b:(int)b c:(int)c { … } -(void)fooWithA:(int)a b:(int)b { [self fooWithA:a b:b c:0]; } For C : there’s nothing special added to the C subset by using ObjC. Anything that cannot be done in pure C can’t be done by compiling in ObjC …

Read more

Creating methods with infinite parameters?

With the params keyword. Here is an example: public int SumThemAll(params int[] numbers) { return numbers.Sum(); } public void SumThemAllAndPrintInString(string s, params int[] numbers) { Console.WriteLine(string.Format(s, SumThemAll(numbers))); } public void MyFunction() { int result = SumThemAll(2, 3, 4, 42); SumThemAllAndPrintInString(“The result is: {0}”, 1, 2, 3); } The code shows various things. First of all …

Read more

How do I pass variables across functions? [duplicate]

This is what is actually happening: global_list = [] def defineAList(): local_list = [‘1′,’2′,’3’] print “For checking purposes: in defineAList, list is”, local_list return local_list def useTheList(passed_list): print “For checking purposes: in useTheList, list is”, passed_list def main(): # returned list is ignored returned_list = defineAList() # passed_list inside useTheList is set to global_list useTheList(global_list) …

Read more