Skip to content

Instantly share code, notes, and snippets.

@lucholaf
Created November 20, 2014 13:45
Show Gist options
  • Save lucholaf/4c49164ffbeb20034cdf to your computer and use it in GitHub Desktop.
Save lucholaf/4c49164ffbeb20034cdf to your computer and use it in GitHub Desktop.
iOS dev notes
WWDC 2013 - #???: What's new in Foundation Networking
-----------------------------------------------------
. NSURLConnection, configured through NSURLRequest. Has a global storage for cookies, cache, etc.
. NSURLSession, replaces NSURLConnection, per object configurable.
. Uploads/Downloads through the filesystem. Can be done Out-of-process, but not a regular data request.
. NSURLSessionTask per request, represents the status and progress. Cancel, Suspend, Resume.
. Per session policies: cache, cookies, credentials.
. backgroundSessionConfiguration
. Background Transfers
WWDC 2013 - #203: What's new in Cocoa Touch
-------------------------------------------
. NSURLSession replaces NSURLConnection.
. UIView tintColor, affects all subviews.
. new key frame animation: animateKeyFramesWithDuration:...
. UIViewController.wantsFullScreenLayout deprecated! is YES all the time.
. UIExtendedEdge is UIExtendedEdgeAll by default.
. preferredContentSize, will be used all over in iOS 7, useful for subViewControllers.
. UIStatusBarStyle only affects text, since background will be always transparent.
. Custom Transitions, check transitionDelegate, called when/how.
. State Restoration...
. UIDynamicBehavior: fluid responsive animations, behaves like a tree, they can be nested. Attachment, collision, gravity, push, snap.
. Dynamic Text, preferredFontForTextStyle: THIS method is very very important.
. NSTextContainer, NSLayoutManager, NSTextStorage.
WWDC 2013 - #206: Getting Started with UIKit Dynamics
-----------------------------------------------------
. content is king.
. core animation, UIView, motion effects (parallax).
. UIDynamicBehavior contains views.
. UIDynamicAnimator contains UIDynamicBehavior (which are composable and subclassable).
. translatesReferenceBoundsIntoBoundaries.
. addBoundaryWithIdentifier:fromPoint:toPoint:.
. snap: move interpolating to a position and leave it without rotation.
. friction, resistance, elasticity, density, allowsRotation.
. add angular or linear velocities from a gesture.
. UIDynamicItem protocol: center, bounds, transform.
. CollectionViewLayoutAttributes.
. you can initialize an animator with a layout.
WWDC 2013 - #202: Advanced Techniques with UIKit Dynamics
---------------------------------------------------------
. UIDynamicAnimator detects when the system rests and stop computing.
. UIDynamicAnimator just changes 'center', will not be aware if center, bounds or transform changes externally. In this later case, remove and add the behavior again.
. CollectionViews... 3 ways to use dynamics:
- specific animation: create an animator and discard it later.
- animate a subset.
- build an entire layout: use it for small data sources!
. UIDynamicAnimator:layoutAttributesForCellAtIndexPath
. continue on min 23...
WWDC 2013 - #210: Introducing Text Kit
--------------------------------------
. Fast modern text layout and rendering engine.
. Built on top of Core Text.
. All text-components were re-written on top of text kit.
. paginated layouts, texts in columns, rich text, exclusion paths.
. text folding, custom truncation.
. Kerning and Ligature ON by default!
. Dynamic Type: small, medium, large
. Font descriptors.
. Symbolic traits: regular, bold, italic, expanded, constraint, line spacing, etc.
. NSTextContainer: coordinate system and geometry.
. NSLayoutManager...
. Glyph: one or more characters on screen.
. Any kind of custom links on the texts!
. Text attachments... you can add photos and text will adapt.
. [myFont lineHeight] whole line.
. [myFont capHeight] from the base (no cuenta el palito de la 'g' por ejemplo).
. [myFont leading] space between lines.
. UIContentSizeCategoryDidChangeNotification: invalidate intrinsic content size by resetting the font if using auto-layout.
WWDC 2012 - #219: Advanced Collection Views and Building Custom Layouts
-----------------------------------------------------------------------
. UICollectionViewLayoutAttributes: one per view and has the attributes: center, size, alpha, transform, zIndex
. The Extensible Delegate: UICollectionViewDelegateFlowLayout extends UICollectionViewDelegate, you can set the delegate to the view collection, and it will call the appropriate new methods.
. -invalidateLayout when the model changes or implicit invalidations with performBatchUpdates:completion:
. pinch resizing gesture.
. going fully custom (no FlowLayout subclass), when you want something no grid like.
. order of operations (fully custom): prepareLayout, collectionViewContentSize, layoutAttributesForElementsInRect
WWDC 2012 - #202: Introduction to Auto Layout
---------------------------------------------
. constraint-based layout system.
. Visual Format Language: constraintsWithVisualFormat:
. constraints has priorities!
. layout process is bottom-up.
. po [[UIWindow keyWindow] _autoLayout] to see if there is something AMBIGUOUS.
. translatesAutoresizingMaskIntoConstraints
WWDC 2011 - #121: Understanding UIKit Rendering
-----------------------------------------------
. CoreAnimation uses pixels (640x960), not points! so try to do calculations on UIKit.
. Frame changes with transformation! but not the bounds nor center. This happens because frame is a calculated property.
. view.center = layer.position
. view.center = layer.affineTransform
. layer.transform is for 3D.
. layer.anchorPoint ;)
. view.layer.contents should not be touched directly.
. drawRect: consumes memory because it needs to generate a drawing buffer, be careful and try to use UIImageView instead.
. CATransaction is implicit used when changing properties of views and commit when run loop is complete.
. Avoid offscreen rendering: it's when can't draw directly to the framebuffer.
. Layer rasterization: when doing offscreen rendering BUT you're sure the view's content won't change and you tell the system to cache the drawing.
WWDC 2012 - #238: iOS App Performance: Graphics and Animations
--------------------------------------------------------------
. drawRect: string and image drawing is slow.
. call setNeedsDisplay only when needed.
. avoid overriding drawRect: for instance UIRectFill is slower and consumes more memory than view.backgroundColor.
. try to use drawRect: with the rect and setNeedsDisplayInRect: in the same way.
. when using images, try to use UIImageView since it can use CGImage data directly, not the case for drawRect: that has to create a backing store for it.
. image decoding or drawing, try to do it in the background.
. PNG and JPEG, not other formats, they are not optimized for iOS.
. view.layer.drawsAsynchronously, GPU drawing, high setup cost, high memory hit, good for lots of drawing into a single view.
. when drawing over and over above a background, you can merge each new draw to the background and reuse that view to use for the next draw, kind of accumulative drawing. Core Graphics to the rescue.
. when having a performance problem, you have to see if it's CPU bound or GPU bound.
. 100% device usage is a sign of GPU bound.
. to reduce view composition, use flattening, which means reducing hierarchies and use more CPU than GPU.
. flattening hurts responsiveness because of the up-front CPU usage.
. flattening means to implement drawRect: and avoid view hierarchies and that way increase smoothness at the cost of responsiveness.
. view.layer.shouldRasterize: another way to decrease usage of GPU.
. offscreen rendering: when doing masking and clipping, it will happen.
. check 'Color hits Green and Misses Red' to see if shouldRasterize is working.
WWDC 2012 - #242: iOS App Performance: Memory
---------------------------------------------
. avoid running long tasks on main thread, because memory warnings happens there, and that way they can't be delivered.
. UIViewController viewDidUnload -> use that no more.
. avoid spikes of memory, you can use autoreleasepool to avoid that.
. take heap snapshots (Mark Heap) and see how heap grows when repeating actions. e.g: going back and forward into a view controller.
. take a look a reference counting history.
. zombies template on iOS simulator, intercept messages to deallocated objects.
WWDC 2012 - #236: Evolution of View Controllers
-----------------------------------------------
. add: first add child VC to parent, then subview to view, then tell child it was moved to parent.
. remove: first tell child it was moved to parent 'nil', then remove subview, then remove child VC from parent.
. parents make the rules and children follows.
. layout is independent of interface orientation *.
. VC containment: many VC on the screen at once.
. VC containment forwards appearance methods.
. * VC containment allows child VC not to rotate if they do not want, even if parent rotates.
. view*unload is deprecated since is not needed for performance reasons anymore, you can use didReceiveMemoryWarnings in case of unloading resources.
. updateViewConstraints: to layout views...
. VCs have state restoration in case they are killed.
. [window setRootViewController:] to receive rotation calls...
. a VC should never set its own frame.
#409: Learning Instruments
#706: Networking Best Practices
#506: Optimizing 2D Graphics and Animation Performance
#601: Optimizing Web Content in UIWebViews and Websites on iOS
AutoLayout
----------
. setTranslatesAutoresizingMaskIntoConstraints is used when creating UIViews manually
. self.edgesForExtendedLayout = UIRectEdgeNone not to go full screen
. topLayoutGuide and bottomLayoutGuide to indicate top and bottom offsets of areas that should not overlap
Core Data
---------
. one context per thread
. OR context + store per thread, more memory but less locking code areas and harder to communicate changes between contexts.
. if using != context, you must pass objects by the ID and the request the whole object from that thread.
. @synchronized(self) {}
Drawing
-------
. CALayers do not have touch support
. CALayers:setContentsScale must be used for self created layers
. (CGSize)intrinsicContentSize (which should call systemLayoutSizeFittingSize:) is very important with auto layout
Foundation
----------
. do not use isKindOfClass: for class clusters, an inmutable class could report is mutable and things like that.
iPad version
------------
universal -> 1 target and 2 resources dir
specific -> 2 targets
auto-sizing! essential, use anchor or proportional size increase
on ipad -> UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
user availability macros to target lower iphone sdks and if ([newerClass class]) {} (must-use LLVM and Clang) or NSClassFromString (prior 4.1 sdk). Also instancesRespondToSelector:
Default-Landscape.jpg and Default-Portrait.jpg
UISupportedInterfaceOrientations in Info.plist
CFBundleIconFiles in Info.plist
Support both variants of an orientation!!! si solo corre en landscape, que corra en la otra variante tambien (arriba/abajo)
Error Handling
--------------
domain -> posix, mach, cocoa, webkit, xmlparser, etc.
code -> specific domain code error (search for headers)
NSError for user level errors.
NSException for programming errors.
Views
-----
UINib to load views made with IB that are not associated to a view controller.
LayoutSubviews should be used when autosizemasks are not enough
Threads
-------
. NSOperation can cancel, set number of concurrent operations and create dependencies.
. GCD queues should use dispatch_retain/dispatch_release when are passed around.
. GCD queues can be suspended.
. semaphores to to specify certain amount of resources available.
. group of queues so you can wait for all of them to finish.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment