When should I use the “self” keyword?

后端 未结 6 1799
执念已碎
执念已碎 2020-12-06 02:53

When should I be using the self expression in my iphone development applications? say i have 2 fields: UITextField *text1; and NSString *str1

6条回答
  •  囚心锁ツ
    2020-12-06 03:05

    I don't know anything about objective-c, but this looks a lot like this keyword from other languages (like C++, C#, Java, PHP, and others). If so, then my advice is to use it always. That way, if you ever (accidentally) define a local variable with the same name, your code won't break.

    However, I must also add, that this is somewhat of a religious debate with a history of flamewars in programmer communities. So take this advice with a grain of salt and use whatever seems to make most sense to you. Just be consistent about it.

提交回复
热议问题