2013-09-23 62 views
0

我有一個方法來執行一些塊操作(讓我們說數據庫事務)與4個不同的條件(2個布爾參數)。那麼在包括Apple在內的許多約定中,block參數應該是最後一個,但我們不應該首先將bool參數放在最前面。 你覺得我應該說這種方法嗎?該方法命名爲什麼?

- (void)performDatabaseTransactionWithSynchronously:(BOOL)synchronously 
           isWritterOperation:(BOOL)isWritter 
             transaction:(TransactionBlock)block 

- (void)performDatabaseTransactionWithSynchronously:(BOOL)synchronously 
           isWritterOperation:(BOOL)isWritter 
            withTransaction:(TransactionBlock)block 

- (void)performDatabaseTransaction:(TransactionBlock)block 
        synchronously:(BOOL)synchronously 
       isWritterOperation:(BOOL)isWritter 

或任何其他人呢?

+0

最後一個看起來整潔。 – domi

+0

如果它也必須接受NSError **參數呢? –

+0

@domi,該塊應該是最後一個參數,請參閱我的評論下的答案。 – Stas

回答

1

我的版本是:

- (void)performDatabaseTransactionSynchronously:(BOOL)synchronously 
           isWriterOperation:(BOOL)isWriter 
             withBlock:(TransactionBlock)block 
+1

只需在塊參數之前添加它即可。我會把塊留在它的位置上,因爲塊可能包含許多代碼串和其他參數(在塊之後)可能不可見 – Stas

+0

我同意這條評論,它也在我的約定中。 –

+0

也許你接受答案吧? – Stas

1

現在我用

- (BOOL)performDatabaseTransactionWithDeffered:(BOOL)useDeferred 
          isWriterOperation:(BOOL)isWritter 
             error:(NSError * __autoreleasing *)error 
            usingBlock:(TransactionBlock)block 

- (void)performDatabaseTransactionAsynchronouslyWithDeffered:(BOOL)useDeferred 
              isWriterOperation:(BOOL)isWriter 
               transaction:(TransactionBlock)block 
                completion:(CompletionBlock)completion 

任何其他的答案嗎?

+1

相當不錯的決定 – Stas

相關問題