Classification - Where is the implementation of the extension method written? objective-c
迷茫
迷茫 2017-05-02 09:38:18
0
2
807

1. Check the information: Extension is often called an anonymous Category (for example: in the string class extension extension, the added attributes str1 and show method are private,
can only be used in the String class Accessible.
Excuse me: I have a question: What does it mean that the added attributes can only be accessed in the string class?
I wrote the NSString test.h extension and added @property. NSString *name attribute.
In other places, I can access: NSString *str1 = @"hello ";
str1.name. Is this considered access?
2. The extension only has one .h file. . If I add a method. In which file is this method implemented?

3. Deep copy, shallow copy. Only the copy of immutable object NSString is a shallow copy. Everything else is a deep copy. I prepared these interview questions and understood them all.

I would like to ask, what are the uses of [str1 copy], [mutStr2 mutCopy]? I ask a lot of questions during interviews, but they don’t seem to be used much in practice.
4. Lazy loading of iOS design patterns. I saw such an introduction. Design patterns include proxy pattern, MVC, singleton, and observation patterns. Is lazy loading also a design pattern? ? ? ? ! ! !

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
滿天的星座

To add attributes to category, you need to implement its getter/setter methods
扩展只有一个.h文件。如果我加上了一个方法。这个方法实现在哪个 文件中?
The implementation is of course an .m file

当属性类型为 NSString 时,经常用此特质来保护其封装性,因为传递给设置方法的新值有可能指向一个 NSMutableString 类的实例。这个类是 NSString 的子类,表示一种可修改其值的字符串,此时若是不拷贝字符串,那么设置完属性之后,字符串的值就可能会在对象不知情的情况下遭人更改。所以,这时就要拷贝一份“不可变” (immutable)的字符串,确保对象中的字符串值不会无意间变动。只要实现属性所用的对象是“可变的” (mutable),就应该在设置新属性值时拷贝一份。
仅有的幸福

heathWang talked about the first three, I will try to answer the last one. Granted, iOS is a bit confusing in this regard. As you said, lazy loading, observers, singletons, and proxies are design patterns. MVC and MVVM are called framework patterns. AFNetwork and Foundation are called frameworks.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template