strongloop-community / loopback-sdk-ios

iOS Client SDK for the LoopBack framework.
Other
76 stars 39 forks source link

Usage of typedef for success/failure block type declarations causes Swift usability issue #99

Closed hideya closed 8 years ago

hideya commented 8 years ago

For example, PersistedModel's findById method is declared as the following:

- (void)findById:(id)_id
         success:(LBPersistedModelFindSuccessBlock)success
         failure:(SLFailureBlock)failure;

where, LBPersistedModelFindSuccessBlock is typedef'ed as void(^)(LBPersistedModel *model).

When coding in Swift, completion for findById: becomes:

findById( _id: AnyObject! , success: LBPersistedModelFindSuccessBlock! , failure: SLFailureBlock! )

rather than expanding the typedefs like the following (like when we code in Obj-C):

findById( _id: AnyObject! , success: ((LBPersistedModel!) -> Void)! , failure: ((NSError!) -> Void)! )

I think this damages coding experience quite a bit.

In order to avoid this, success/failure block should be declared with plain types (and all the typedefs for success blocks might better be deprecated as they are not really necessary).

hideya commented 8 years ago

@bajtos while working on this, I realised that there are so many lines I need to touch if I try to get rid of all the typedefs used for the success block types. I'm not sure if it is worthwhile because of possibility of including subtile bugs and as we are moving towards swagger-codegen for Swift support.

So, here is a proposal -- cleanup typedefs added after ver 1.3.2, mark extra typedefs "deprecated", and leave other legacy typedefs untouched. This should cleans up the codebase into a better shape without touching too many lines. Does this sound good?

hideya commented 8 years ago

Closing this as PR https://github.com/strongloop/loopback-sdk-ios/pull/101 (that implements the above mentioned proposal) has been merged.