如何创建私有的Pod

公司的框架代码大多数时候是需要保密的,而手动的复制导入比较麻烦,这时候我们可以创建私有 Pod 来方便我们的日常开发工作,本文是我创建私有 Pod 的笔记。

Cocoapods 提供了 pod lib create [pod name] 来创建私有库工程,但是有个 embedded dylibs/frameworks are only supported on iOS 8.0 and later 的问题。 意思是只有部署 iOS 8 以上的应用才能使用它,所以要支持 iOS 8 以下的应用的 Pod 我们还是得手动创建,详细步骤如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ mkdir AJFrame

// Create static library
Xcode > File > New > Project... > Framework & Library > Cocoa Touch Static Libray 

// Create dev app
Xcode > File > New > Project... > Single View Application

// Result 
AJFrame
├── AJFrame
│   ├── AJFrame.xcodeproj
│   ├── AJFrameTests
│   ├── Classes
├── AJFrame.podspec
├── AJFrameDevApp
│   ├── AJFrameDevApp
│   ├── AJFrameDevApp.xcodeproj
│   ├── AJFrameDevApp.xcworkspace
│   ├── AJFrameDevAppTests
│   ├── Podfile
│   ├── Podfile.lock
│   └── Pods
└── LICENSE
继续阅读

(翻译)How to Play, Record, and Edit Videos in iOS

录制视频(并用代码播放它们)是你可以用手机来做的最酷的事情之一,但不是所有的应用都利用了它们。它需要 AVFoundation 框架,AVFoundation 从 Lion(10.7)开始是 OS X 的一部分,Apple 在 2010 年将它加入到 iOS 4.

从那之后 AVFoundation 也有了相当多的成长,现在拥有 100 多个类。本教程覆盖媒体播放和一些轻量级编辑来让你开始使用 AVFoundation.

AVAsset

它是表示基于时间的视听媒体的抽象类例如视频和音频。每个assert包含用于展示或处理的记录集合,可以是任意一种通用媒体类型,包括但不仅限于音频,视频,文本,closed captions 和 subtitles。

一个AVAsset对象定义了定义记录的属性集合,它构成asset。一个记录用一个AVAssetTrack实例表示。

在典型的简单情况下,一个记录代表一个音频组件,另一个代表视频组件;在复杂的合成器中,可能会有多个重叠的音频和视频记录。你将会把合成的视频和音频文件表示成AVAsset对象。

AVComposition

An AVCompositionobject combines media data from multiple file-based sources in a custom temporal arrangement in order to present or process it together. All file-based audiovisual assets are eligible to be combined, regardless of container type.

一个AVComposition对象用自定义的时间顺序排列混合来自多个基于文件源的媒体使得可以一起显示或处理。所有基于文件的视听asset都可以混合,而不用管容器类型。

At its top level, an AVComposition is a collection of tracks, each presenting media of a specific type such as audio or video, according to a timeline. Each track is represented by an instance of AVCompositionTrack.

在它的上一级,AVComposition是记录的集合,每个依据时间线展示像音频或视频的媒体类型。每个记录由一个AVCompositionTrack实例代表。

AVMutableComposition and AVMutableCompositionTrack

A higher-level interface for constructing compositions is also presented by AVMutableComposition and AVMutableCompositionTrack. These objects offer insertion, removal, and scaling operations without direct manipulation of the trackSegment arrays of composition tracks.

AVMutableComposition and AVMutableCompositionTrack make use of higher-level constructs such as AVAsset and AVAssetTrack. This means the client can make use of the same references to candidate sources that it would have created in order to inspect or preview them prior to inclusion in a composition.

In short, you have an AVMutableComposition and you can add multiple AVMutableCompositionTrack instances to it. Each AVMutableCompositionTrack will have a separate media asset.

And the Rest

In order to apply a CGAffineTransform to a track, you will make use of AVVideoCompositionInstruction and AVVideoComposition. An AVVideoCompositionInstruction object represents an operation to be performed by a compositor. The object contains multiple AVMutableVideoCompositionLayerInstruction objects.

You use an AVVideoCompositionLayerInstruction object to modify the transform and opacity ramps to apply to a given track in an AV composition.

AVMutableVideoCompositionLayerInstruction is a mutable subclass of AVVideoCompositionLayerInstruction.

An AVVideoComposition object maintains an array of instructions to perform its composition, and an AVMutableVideoComposition object represents a mutable video composition.

Conclusion

To sum it all up:

You have a main AVMutableComposition object that contains multiple AVMutableCompositionTrack instances. Each track represents an asset.

You have AVMutableVideoComposition objects that contain multiple AVMutableVideoCompositionInstructions.

Each AVMutableVideoCompositionInstruction contains multiple AVMutableVideoCompositionLayerInstruction instances.

Each layer instruction is used to apply a certain transform to a given track.

原文

iOS 面试题汇总(一)

1.Explain method swizzling. When you would use it?

A:Method swizzling is a feature of dynamic of Objective-C that use a new method implementation replace the original. When the original implement doesn’t meet my need, I will use this technology.

2.Take three objects: a grandparent, parent and child. The grandparent retains the parent, the parent retains the child and the child retains the parent. The grandparent releases the parent. Explain what happens.

A:It causes strong reference cycle, and results as memory leaks.

3.What happens when you invoke a method on a nil pointer?

A:返回0

Reference:nil / Nil / NULL / NSNull

4.Give two separate and independent reasons why retainCount should never be used in shipping code.

A:

There should be no reason to explicitly ask an object what its retain count is (see retainCount). The result is often misleading, as you may be unaware of what framework objects have retained an object in which you are interested. In debugging memory management issues, you should be concerned only with ensuring that your code adheres to the ownership rules.

  1. 结果不正确,因为你不知道框架中哪些对象已经引用了你感兴趣的对象;
  2. 产品代码中不应该包含无用代码。

5.Explain your process for tracing and fixing a memory leak.

A:

  1. Launch Instruments, select Leaks instrument;
  2. Use App normal;
  3. Notice spike on timeline pane;
  4. Check spike is normal;
  5. Fix any where that cause memory leak;

We also can use Allocations:

  1. Launch Instruments, select Allocations instrument;
  2. Use App normal;
  3. Make generation when state change;
  4. Compare gerations to find out memory leak;
  5. Fix memory leak;

Reference:Instruments Tutorial for iOS: How To Debug Memory Leaks

6.Explain how an autorelease pool works at the runtime level.

A:As its name, it works like a pool, any object called autorelease method be throw to this pool, all object in autorelease pool will recieve a release method when it drain that occured at each event loop end.

7.When dealing with property declarations, what is the difference between atomic and non-atomic?

A: atomic是指存在竞争赋值时,我们会得到某次完整的赋值,而nonatomic则可能是几次赋值共同组合。

1
2
3
4
5
6
7
8
@property CGRect domain;

<b>thread 1:</b> puppy.domain = CGRectMake (1.0, 2.0, 3.0, 4.0);
<b>thread 2:</b> puppy.domain = CGRectMake (10.0, 20.0, 30.0, 40.0);

atomic意味着在竞争赋值的情况下得到的结果是CGRectMake (1.0, 2.0, 3.0, 4.0)或者CGRectMake (10.0, 20.0, 30.0, 40.0)。

noatomic情况得到的结果可能是CGRectMake (1.0, 2.0, 30.0, 40.0)这种两次组合的乱码。

再进一步,atomic是不是意味着代码是线程安全的呢?不是。atomic修饰符可以保证property的读写操作是串行的,但如果对象的指针不是atomic修饰的,代码仍然不是线程安全的。

8.In C, how would you reverse a string as quickly as possible?

9.Which is faster: to iterate through an NSArray or an NSSet?

A: NSArray

Reference:NSArray or NSSet, NSDictionary or NSMapTable

10.Explain how code signing works.

A:签名软件先将代码和资源使用单向 hash 算法计算出一系列的 hash 值,之后使用签名者提供的私钥来加密这些 hash 值,加密后的 hash 值存储在代码包中,在代码包中还包含签名者的证书,证书是由 Apple 签发的,能证明签名者的身份,证书里还包含签名者的公钥,操作系统之后可以使用相同的 hash 算法计算代码包里代码和资源的 hash,然后将 hash 值和用公钥解密的 hash 对比,这样就能保证代码并未被修改和确认它的来源,这就是代码签名的大致原理。

11.What is posing in Objective-C?

12.List six instruments that are part of the standard.

A:

  1. Time Profiler
  2. Leaks
  3. Zombies
  4. Allocations
  5. Activity Monitor
  6. Core Animation
  7. Network

13.What are the differences between copy and retain?

A: copy是新创建一个对象副本;retain则是对象引用计数加一。

14.What is the difference between frames and bounds?

A:

The frame property contains the frame rectangle, which specifies the size and location of the view in its superview’s coordinate system. The bounds property contains the bounds rectangle, which specifies the size of the view (and its content origin) in the view’s own local coordinate system.

extend:

Does frames' size always equal to bounds' size?
A: No, if view’s transform is not CGAffineTransformIdentity, its may not equal.

15.What happens when the following code executes? Ball *ball = [[[[Ball alloc] init] autorelease] autorelease];

A: The object gets released twice when the autorelease pool is drain, so it may causes app crash.

Reference:Autoreleasing twice an object

16.List the five iOS app states.

A:

State Description
Not Running The app has not been launched or was running but was terminated by the system.
Inactive The app is running in the foreground but is currently not receiving events. (It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state.
Active The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
Background The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state. For information about how to execute code while in the background
Suspended The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code.

When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.

Reference:

o iOS Interview Questions