Sean's Note: 12月 2014

2014年12月28日 星期日

Setting up TortoiseGit with GitHub

安裝環境

  1. 安裝 TortoiseGit 1.8.12.0。
  2. 安裝 Git for Windows 1.9.5。

建立 Git 的 repository

  1. 在要作為 repository 的資料夾上按右鍵 "Get Create repository here...",跳出視窗時
    不需勾選 "Make it Bare",完成後資料夾裡就會出現一個 .git 的隱藏資料夾。
  2. 在 Git 的 Settings -> Git 裡設定 User Info。

Commit 到 Local 端

  1. 在資料夾上按滑鼠右鍵 "Git Commit -> "master"...",此時只是 commit 程式碼到  Local 端而已,還沒 commit 到 GitHub。

Push/Pull 到 GitHub

  1. 先到 GitHub 上建立一個新的 repository。
  2. 點進該新的 repository 後,右側欄可以看到 clone URL 的選項,複製 SSH 的。
  3. 在 Git 的 Settings -> Remote 裡加入一個新的 remote,名字隨便取,URL 貼上剛剛所複製的。

    SSH URL
  4. 要上傳程式碼到 GitHub 之前,要先建立 key,在 TortoiseGit 的資料夾裡找到 "PuTTYgen" 後開啟,滑鼠在中間空白的區域亂滑以建立 key,然後 "Save private key" 到某個地方。

    PuTTY Key Generator
  5. 再把 Public Key 給 copy 下來,到 GitHub 的 Settings -> Personal settings -> SSH keys -> Add SSH key,然後貼上。
  6. 在 TortoiseGit 的資料夾裡找到 "Pageant" 開啟,加入剛剛建立的 private key。

    Pageant
  7. 終於,可以開始 Push 程式碼啦!?
    在資料夾上按滑鼠右鍵 "TortoiseGit" -> "Push ...",跳出 Push 的視窗,OK 送出。

    Push
  8. 如果遇到 error: failed to push some refs to '...........'
    git did not exit cleanly (exit code 1),那就先把 repository 從 GitHub Pull 回來一次,就可以 Push 了!
git did not exit cleanly (exit code 1)


2014年12月27日 星期六

[Eclipse] Java was started but returned exit code=13

至從把 Java 從 7 更新到 8 後,開 Eclipse 突然出現了錯誤:

Java was started but returned exit code=13

後來發現 java 更新到 32bit 的版本,但 Eclipse 用的是 64bit 的版本,

所以在重裝一次 64bit 的 Java 8 就好了。

exit code=13

2014年12月22日 星期一

[讀書筆記] Effective Objective-C - Chapter 2

2. Objects, Messaging, and the Runtime

Item 6: Understand Properties

  1. Four categories of attributes can be applied: 
    1. Atomicity: atomic(default)/nonatomic
    2. Read/Write: readwrite/readonly
    3. Memory-Management Semantics: assign, strong, weak, unsafe_unretained, copy
    4. Methods Names: getter=<name>, setter=<name>
  2. If you implement your own accessors, you should make them adhere to specified attributes yourself.
  3. Never use use your own accessors in an init(or dealloc) method.
  4. All properties are declared nonatomic on iOS because the locking introduces such an overhead on iOS, and it doesn't ensure thread safety.

Item 7: Access Instance Variables Primarily Directly When Accessing Them Internally

  1. Prefer to read data directly through instance variables internally and to write data through properties internally. 
Additional Study: Should I Use a Property or an Instance Variable?

Item 8: Understand Object Equality

  1. Use isEqualToString: is faster than calling isEqual:.
  2. Objects that are equal must have the same hash, but objects that have the same hash do not necessarily have to be equal.
  3. Be aware of what can happen when you mutate on object that's in a collection.

Item 9: Use the Class Cluster Pattern to Hide Implementation Detail

  1. Factory pattern is one way of creating a class cluster.
  2. There is no abstract base class for Objective-C. Instead, convention foe how to use a class should be made in documentation.
  3. Most of collection classes are class clusters, such as NSArray and NSMutableArray.
  4. Should use isKindOfClass: rather than class when comparing class cluster.

Item 10: Use Associated Objects to Attach Custom Data to Existing Classes

  1. objc_setAssociatedObject, objc_getAssociatedObject
  2. The accessing of associated objects is functionally similar to imaging that the object is an NSDictionary. An import difference is that key is treated purely as an opaque pointer. Thus, it's common to use static global variables for the keys.
  3. Can be used on delegate protocol methods.
  4. Can easily introduce hard-to-find bugs. 

Item 11: Understand the Role of objc_msgSend
  1. void objc_msgSend(id self, SEL cmd, ...)
  2. The function loos through the list of methods implemented by the receiver's class. It caches the result in a fast map, one for each class.

Item 12: Understand Message Forwarding

  1. It's not compile-time error to send a message to a class that it doesn't understand, since methods can be added to classes at runtime. When it receives a method that it doesn't understand, an object goes through message forwarding.
  2. The forwarding pathways are split into two avenues:
    Dynamic Method Resolution
    +(BOOL)resolveInstanceMethod:(SEL)selector
    +(BOOL)resolveClassMethod:(SEL)selector

    Replacement Receiver
    -(id)forwardingTargetForSelector:(SEL)selector
    Full Forwarding Mechanism
    -(void)forwardInvocation:(NSInvocation*)invocaiton

Item 13: Consider Method Swizzling to Debug Opaque Methods

  1. Swizzling is the process of swapping one method implementation for another, usually to add functionality to the original implementation. 
  2. class_getInstanceMethod, method_exchangeImplementaitons
  3. Useful for debugging.

Item 14: Understand What a Class Object Is

  1. Always prefer introspection methods were possible, rather than direct comparison of class objects, since the object may implement message forwarding.

 

2014年12月11日 星期四

[讀書筆記] Effective Objective-C - Chapter1

1. Accustoming Yourself to Objective-C

Item 1: Familiarize Yourself with Objective-C's Roots

  1. It uses messaging structure with dynamic binding rather than function calling.
  2. Memory for objects is always allocated in heap space and never on the stack.
  3. Some variables like CGRect not holding Objective-C objects are using stack space.

Item 2: Minimize Importing Headers in Headers

  1. Use forward declaration to decrease compile time. EX: @class EOCEmployer;
  2. Using forward declaration also alleviates the problem of both classes referring to each other.

Item 3: Prefer Literal Syntax over the Equivalent Methods

  • Literal Arrays
    NSArray *arrayA = [NSArray arrayWithObjects:object1, object2, object3, nil];NSArray *arrayB = @[object1, object2, object3];
    If object2 is nil, the literal array, array B, will cause the exception to be thrown, However, arrayA will still be created but will contain only object1.
  • Literal Arrays
    Similar to above.
  • Limitations
    If a mutable variant is required, a mutable copy must be taken.
    EX: NSMutableArray *mutable = [@[@1, @2, @3, @4, @5] mutableCopy]; 

Item 4: Prefer Typed Constants to Preprocessor #define

  1. Type constants have type information(More readable).
  2. The usual convention for constants is to prefix with the letter k for constants that are local to a translation unit. For constants that are exposed outside of a class, it's usual to prefix with the class name.

Item 5: Use Enumerations for States, Options, and Status Codes

  1. C++11 brought some changes like the capability to dictate the underlying type used to store variables of the enumerated type.

2014年12月4日 星期四

ViewPager shows nothing with PagerAdapter

除了要 Override 並實作 instantiateItem 方法之外,
不要忘了 Override isViewFromObject
@Override
public boolean isViewFromObject(View view, Object object) {
    return view==object;
}