You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/11/07 15:01:46 UTC

[GitHub] csantanapr commented on issue #2: Swift 4 support

csantanapr commented on issue #2: Swift 4 support
URL: https://github.com/apache/incubator-openwhisk-runtime-swift/issues/2#issuecomment-342509355
 
 
   
   User can define Codable
   ```swift
   struct Meal: Codable {
       
       //MARK: Properties
       
       var name: String
       var photo: Data
       var rating: Int
       
       //MARK: Initialization
       
       init?(name: String, photo: Data, rating: Int) {
           
           // The name must not be empty
           guard !name.isEmpty else {
               return nil
           }
           
           // The rating must be between 0 and 5 inclusively
           guard (rating >= 0) && (rating <= 5) else {
               return nil
           }
           
           // Initialization should fail if there is no name or if the rating is negative.
           if name.isEmpty || rating < 0  {
               return nil
           }
           
           // Initialize stored properties.
           self.name = name
           self.photo = photo
           self.rating = rating
           
       }
   }
   ```
   
   Action
   ```swift
   func storeHandler(meal: Meal, completion: (Meal?, RequestError?) -> Void ) -> Void {
           mealStore[meal.name] = meal 
           completion(mealStore[meal.name], nil)
       }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services