This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func stringByStrippingHTMLElementsWithRegex() -> String { | |
let trimmedString = self.stringByReplacingOccurrencesOfString("<[^>]+>", withString: "", options: .RegularExpressionSearch, range: nil) | |
let trimmedStringFromNewLine = trimmedString.stringByReplacingOccurrencesOfString("\n", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil) | |
let trimmedStringFromWhiteSpaces = trimmedStringFromNewLine.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) | |
return trimmedStringFromWhiteSpaces | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func stringByStrippingHTMLElementsNativeWay() -> String { | |
let encodedData = self.dataUsingEncoding(NSUTF8StringEncoding)! | |
let attributedOptions : [String: AnyObject] = [ | |
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, | |
NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding | |
] | |
var attributedString: NSAttributedString? | |
do { | |
attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
<li>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu.Cras consequat.</li> | |
<li>Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</li><li>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.</li><li>Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.</li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct User { | |
let first: String? //optional with value | |
let last: String? //optional with wrong key | |
let headline: String? //optional with null | |
let isEmployee: Bool // boolean | |
let employeeLevel: EmployeeLevel //enum | |
let socialProfiles: [SocialProfile] //array | |
let friendId: Int //nested property | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"firstname": "Wayne", | |
"lastname": "Walsh", | |
"headline": null, | |
"isEmployee": true, | |
"employee_level": "junior", | |
"resume_url": "https://workable.com", | |
"friends": { | |
"id": 10 | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For models that are ALREADY Swift.Decodable and want to be used inside Argo decodable models | |
protocol SwiftToArgoDecodable: Argo.Decodable, Swift.Decodable where Self.DecodedType == Self {} | |
extension SwiftToArgoDecodable { | |
static func decode(_ json: JSON) -> Decoded<DecodedType> { | |
do { | |
let jsonData = try JSONSerialization.data(withJSONObject: json.JSONObject(), options: []) | |
let decodedValue = try JSONDecoder().decode(Self.self, from: jsonData) | |
return .success(decodedValue) | |
} catch let error { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For models that are ALREADY Argo decodable and want to be used inside Swift decodable models | |
protocol ArgoToSwiftDecodable: Argo.Decodable where Self.DecodedType == Self, Self: Swift.Decodable{} | |
extension ArgoToSwiftDecodable { | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
let json = try container.decode(JSON.self) | |
self = try Self.decode(json).dematerialize() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Argo.JSON: Swift.Decodable { | |
public init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
if let value = try? container.decode(String.self) { | |
self = .string(value) | |
} else if let value = try? container.decode(Int.self) { | |
self = JSON.number(value as NSNumber) | |
} else if let value = try? container.decode(Double.self) { | |
self = JSON.number(value as NSNumber) | |
} else if let value = try? container.decode(Bool.self) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension User: Swift.Decodable {} | |
extension User: ArgoToSwiftDecodable { | |
static func decode(_ json: JSON) -> Decoded<User> { | |
return curry(self.init) | |
<^> json <|? "firstname" | |
<*> json <|? "lastname" | |
<*> json <|? "headline" | |
<*> json <| "isEmployee" | |
<*> json <| "employee_level" | |
<*> json <|| "social_profiles" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def deploy() { | |
stage('Checkout') { | |
checkout scm | |
} | |
stage('Install dependencies') { | |
sh 'gem install bundler' | |
sh 'bundle update' | |
sh 'bundle exec pod repo update' |
OlderNewer