I’d like to return a Cartesian coordinate (x, y), as two ints. The only way I see is to create a class and return an instance of it.
How to return two values from a method in Objective C?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can only return one value from a function (just like C), but the value can be anything, including a struct. And since you can return a struct by value, you can define a function like this (to borrow your example):
This is only really appropriate for small/simple structs.
If you want to return more than one new object, your function should take pointers to the object pointer, thus: