理解Objective-C运行时

Objective-C 运行时对于刚刚踏入 Cocoa/Objective 世界的人是很容易忽 略的 Objective-C 语言的特性之一。原因就是尽管 Objective-C 是一门几个小时之内入门的语言,但是投身 Cocoa 的新手们会花费大量时间在 Cocoa 框架中,试图搞清楚他到底是怎么工作的。 我觉得每个开发者都应该对其有深入的了解,明白一些内部的实现细节,而不仅仅只知道代码 [target doMethodWith:var] 会被编译器转换成 objc_msgSend(target,@selector(doMethodWith:),var1); 而已。了解 Objective-C 运行时的原理有助于你对 Objective-C 语言有更深入的理解,清楚你得 App 是怎么运行的。我觉得这对无论是 Mac/iPhone 新手或者老手都会有所帮助。

我们是如何创建iOS版的Guillotine菜单动画的

原文:How We Created Guillotine Menu Animation for iOS 原作者 @johnsundell

你是否曾经有过这样的疑问?为什么app中几乎是清一色的边栏(sidebar),为什么不把它做成topBar或者bottomBar,甚至cornerBar呢?

[28] Implement strStr()

题目:28. Implement strStr()

Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

题意:

该题目就是实现strstr()函数,该函数C语言原型如下:返回字符串str1在str2中的位置。

[257] Binary Tree Paths

题目:257. Binary Tree Paths

Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 /
2 3
5 All root-to-leaf paths are: [“1->2->5”, “1->3”]

题意:

难度不大,考察树的遍历

解法:

C++版本实现方法:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

	/**
		 * Definition for a binary tree node.
		 * struct TreeNode {
		 *     int val;
		 *     TreeNode *left;
		 *     TreeNode *right;
		 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
		 * };
		 */
	class Solution {
		public:
			vector<string> binaryTreePaths(TreeNode* root) 
			{
				vector<string> results;
				visitTreeNode(root, "", results);
				return results;
			}

		private:
			void visitTreeNode(TreeNode* node, string path, vector<string>& result)
			{
			    if(node == nullptr) return;
				if (!path.empty())
				{
					path += "->";
				}
				path += int2Str(node->val);

				if (node->left == nullptr && node->right == nullptr)
				{
					result.push_back(path);
				}
				else
				{
					if (node->left != nullptr)
					{
						visitTreeNode(node->left, path, result);
					}
					if (node->right != nullptr)
					{
						visitTreeNode(node->right, path, result);
					}
				}
			}

			std::string int2Str(int nValue)
			{
				ostringstream ss;
				ss << nValue;
				return ss.str();
			}
		}

[018] Length Of Last Word

题目:

Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string. If the last word does not exist, return 0. Note: A word is defined as a character sequence consists of non-space characters only. For example, Given s = “Hello World”, return 5.

题意:

难度不大,考虑所有边界情况即可。