在Objective-C大括号 [英] Curly Braces in Objective-c
问题描述
注意:我的问题是基于后检查这个和答案吧。
在一些大的方法,也有code片,你只需要为一段时间活着。举个例子:
1)我有设置我的UI大的方法: UILabel的
的大小,颜色,位置,的UIView的
手势识别器等,了解上述情况,确实是有道理的做这样的事情:
- (无效)setUI
{
//设置其他UI元素
{
//滑动手势添加到swipeUpView
UISwipeGestureRecognizer * swipeGestureUp = [[UISwipeGestureRecognizer页头] initWithTarget:自我行动:@selector(animeViewWithSwipeGesture)]; swipeGestureUp.direction = UISwipeGestureRecognizerDirectionUp;
[_swipeUpView addGestureRecognizer:swipeGestureUp];
} //设置其他UI元素
}
- 基于上面的例子,这是降低应用程序的内存占用量的有效方法是什么?
- 是否有任何关系
@autoreleasepool {}
?
根据上面的例子,这是降低应用程序的内存占用量的有效方法是什么?
块引用>没有。他们甚至不相关。他们都不是他们与
@autoreleasepool
- 花括号的这种用法是打开一个新范围的纯C的方式Note: My question is based after checking this and the answers to it.
In some bigger methods, there are pieces of code that you only want to be alive for a certain period of time. An example:
1) I have a big method that sets my UI:
UILabel's
size, colour, positioning,UIView's
gesture recognisers, etc. Knowing the above, does it makes sense to do something like this:- (void)setUI { //setting other UI elements { // Add the Swipe Gesture to the swipeUpView UISwipeGestureRecognizer *swipeGestureUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(animeViewWithSwipeGesture)]; swipeGestureUp.direction = UISwipeGestureRecognizerDirectionUp; [_swipeUpView addGestureRecognizer:swipeGestureUp]; } // setting other UI elements }
- Based on the above example, is this a valid way of lowering the memory footprint of an application?
- Is there any relation with
@autoreleasepool{}
?解决方案Based on the above example, is this a valid way of lowering the memory footprint of an application?
No. They're not even related. Neither are they related to
@autoreleasepool
- this usage of curly braces is the plain C way of opening a new scope.这篇关于在Objective-C大括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!