0

This question is trivial but I have no idea how to do it

I have this swift code

... = XYZ.auth().currentUser;

... = XYZ.auth().currentUser.phoneNumber;

I want to convert this Swift code to Objective-C code , I want to call auth static method of XYZ class and access the currentUser property

and in the second case I want also to access phoneNumber property of currentUser object

NOTE: I don't know Objective-C but I trying to build ReactNative Module that require from me to do this in Objective-C, currently I haven't the time to learn this language.

1
  • 1
    Most likely [XYZ auth].currentUser.phoneNumber; Commented Aug 28, 2017 at 11:50

2 Answers 2

1

Use the following:

[XYZ auth].currentUser.phoneNumber

The [] syntax is used to send a message (i.e. call a method) on an instance or a class. In this case we are calling a static method auth on class XYZ then we access with . the required property

Sign up to request clarification or add additional context in comments.

4 Comments

Do you know the . syntax is a concise alternative to accessor method calls? You should really clarify it in your answer.
@giorashc Have your read my answer? Take also a look to the documentation EncapsulatingData. I'm not sure what you mean with your statement.
@LorenzoB Read your answer and now I understand your statement.. however the OP asked how to convert the given code to ObjC. The fact that you just gave does not change the correctness of the answer in this context imho
I think so since . and [] does not make any difference since at the end you are always send a message to the object.
1

Even if you have a reply to it, I want to stress out that in Objective-C

Dot Syntax Is a Concise Alternative to Accessor Method Calls

so, the following code:

NSString *firstName = somePerson.firstName;
somePerson.firstName = @"Johnny";

is equivalent to

NSString *firstName = [somePerson firstName]
[somePerson setFirstName:@"Johnny"]

So, in your code:

[XYZ auth].currentUser.phoneNumber

is equivalent to

[[[XYZ auth] currentUser] phoneNumber]

In addition to that, I would like to say that auth method should be renamed to something more meaningful.

My question is: why do you have a static method?

1 Comment

thanks for clarification , ZYX is actually FIRAuth class which is from firebase firebase.google.com/docs/reference/ios/firebaseauth/api/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.