Skip to content

Instantly share code, notes, and snippets.

@zhongge
zhongge / gist:612290f89dd43af10034
Created December 14, 2014 11:48
Q6. Get launched time of Application.
Any time is printed in Console. It isn't application start time.
+ initialize method may not invoked or lazily invoked.
So if you need the launched time of application, you must write the code in main function.
- AppDelegate.m
NSString * startTime;
- main.m
extern NString *startTime;
int main(int argc, char* argv[]) {
@autoreleasepool {
NSDateFormatter *formatter = [NSDateFormatter new];
@zhongge
zhongge / gist:f0bf5a7e7200e74f2fe9
Created December 14, 2014 11:31
What is the bug in this code and what is the consequence?
There is no bug in compile. But It has memory leaks. Because of child.parent = parent when TTChild's @property (automic) TTParent *parent;
How to fix?
As a way of fixing, you can change the TTChild's parent property.
@property (atomic, assign) TTParent *parent;//use assign.
@zhongge
zhongge / gist:ad111629f238b67ff407
Last active August 29, 2015 14:11
What is difference between atomic and nonatomic properties?Which is default for synthesized properties?When would you use one vs. the others?
1. What is difference between atomic and nonatomic properties?
One of the primary challenges of multi-threaded programming.
Atomic properties are necessary in a reference counted multi threaded environment in order to stop objects from disappearing before a thread has a chance to retain them.
In nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than "atomic".
2. Which is default for synthesized properties?
It is nonatomic.
With "atomic", the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, regardless of setter activity on any other thread.
3. When would you use one vs. the others?
I have used the "atomic" for multi-threading. In general, i have used the nonatomic property.
There are two ways
1. Use autolayout constraint in storyboard or xib.
When use autolayout contraints, you must layout of element of UIView in viewDidLayout of UIViewController.
2. In the code, use setFrame:.
@zhongge
zhongge / gist:96f7206baa36f7f11a98
Created December 14, 2014 10:44
Identify the bug in the following code
If TTWaitController hasn't xib or storyboard, TTWaitController hasn't view.
So you couldn't see the screen.
Fix: You must override TTWaitController's loadView.
- (void)loadview {
self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
}
@zhongge
zhongge / gist:2584ee25f8c9c287e776
Created December 14, 2014 09:11
what is the purpose of the reuse identifier?
The reuse identifier is associated with a UITableViewCell object that the table-view’s delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in initWithFrame:reuseIdentifier: and cannot be changed thereafter. A UITableView object maintains a queue (or list) of the currently reusable cells, each with its own reuse identifier, and makes them available to the delegate in the dequeueReusableCellWithIdentifier: method.