Skip to content

Commit e73375b

Browse files
committed
moved code question into thread management
1 parent ff09703 commit e73375b

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

README.md

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Use the Table of Contents to practice and test your knowledge. It doesn't show t
1515
- What is the delegation pattern?
1616
- What is MVC?
1717
- What is MVVM?
18-
- [Code Questions](https://github.com/onthecodepath/iOS-Interview-Questions#code-questions)
1918
- [Core Data](https://github.com/onthecodepath/iOS-Interview-Questions#core-data)
2019
- What is Core Data?
2120
- When would you use Core Data over NSUserDefault?
@@ -87,37 +86,6 @@ MVVM is an augmented version of MVC where the presentation logic is moved out of
8786

8887
A common occurence in MVC is where you have a massive-view-controller (some joke this is what MVC stands for). In order to shrink the size of your view controller and make the logic and readibility of your code easier to follow along, the MVVM will be used.
8988

90-
## Code Questions
91-
92-
#### Spot the bug that occurs in the code:
93-
94-
```
95-
@interface MyCustomController : UIViewController
96-
97-
@property (strong, nonatomic) UILabel *alert;
98-
99-
@end
100-
101-
@implementation MyCustomController
102-
103-
- (void)viewDidLoad {
104-
CGRect frame = CGRectMake(100, 100, 100, 50);
105-
self.alert = [[UILabel alloc] initWithFrame:frame];
106-
self.alert.text = @"Please wait...";
107-
[self.view addSubview:self.alert];
108-
dispatch_async(
109-
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
110-
^{
111-
sleep(10);
112-
self.alert.text = @"Waiting over";
113-
}
114-
);
115-
}
116-
```
117-
118-
All UI updates must be performed on the main thread. Global dispatch queues do not make any guarantees so code should be modified to run the UI update on the main thread.
119-
120-
12189
## Core Data
12290

12391
#### What is Core Data?
@@ -271,6 +239,34 @@ GCD stands for Grand Central Dispatch. According to [Ray Wenderlich](https://www
271239

272240
Tasks executed *serially* are executed one at a time while tasks that are executed *concurrently* may be executed at the same time.
273241

242+
#### Spot the bug that occurs in the code:
243+
244+
```
245+
@interface MyCustomController : UIViewController
246+
247+
@property (strong, nonatomic) UILabel *alert;
248+
249+
@end
250+
251+
@implementation MyCustomController
252+
253+
- (void)viewDidLoad {
254+
CGRect frame = CGRectMake(100, 100, 100, 50);
255+
self.alert = [[UILabel alloc] initWithFrame:frame];
256+
self.alert.text = @"Please wait...";
257+
[self.view addSubview:self.alert];
258+
dispatch_async(
259+
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
260+
^{
261+
sleep(10);
262+
self.alert.text = @"Waiting over";
263+
}
264+
);
265+
}
266+
```
267+
268+
All UI updates must be performed on the main thread. Global dispatch queues do not make any guarantees so code should be modified to run the UI update on the main thread.
269+
274270
## Unit Testing
275271

276272
#### What is the purpose of unit/UI testing? What are the benefits?

0 commit comments

Comments
 (0)