What's the difference between using obj-c accessors and using dot syntax?

后端 未结 3 1410
故里飘歌
故里飘歌 2020-12-22 10:30

Since I\'ve started on iPhone development I\'ve been kinda confused as to which is the best way to access data as a member in a Class.

Let\'s say I have a class call

3条回答
  •  伪装坚强ぢ
    2020-12-22 10:57

    It doesn't really matter, they are the same thing. The dot syntax is a convenience that's there for you to use, and I feel like it makes your code cleaner.

    The one case where I find that using the dot syntax throws warning or errors from the compiler is if you have have an id object, even if you know it has that property.

    id someReturnedObject = [somethingObject someMysteryObjectAtIndex:5];
    int aValue = 0;
    aValue = someReturnedObject.value; // warning
    aValue = [someReturnedObject value]; // will just do it
    

提交回复
热议问题