Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<Description> : Adding NSAttributed string data extension. #379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ All notable changes to this project will be documented in this file.
1. **Collections**
- `func parallelizedMap<R>(_ each: @escaping (Self.Iterator.Element) -> R) -> [R?]` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/394) by *Khalian*

2. **Dictionary**
2. **Data**
- `var attributedString` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/379) by *Khalian*

3. **Dictionary**
- `func random() -> Value?` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/420) by *Khalian*

3. **FileManager**
4. **FileManager**
- `var documentsDirectoryPath: String?` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/338) by *vilapuigvila*
- `var cachesDirectoryPath: String?` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/338) by *vilapuigvila*

4. **UIStackView**
5. **UIStackView**
- `addArrangedSubviews(_ views: UIView...)` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/396) by *kirakik*
- `init(distribution: UIStackViewDistribution, alignment: UIStackViewAlignment, axis: UILayoutConstraintAxis, spacing: CGFloat)` in [[PR]](https://github.com/goktugyil/ EZSwiftExtensions/pull/396) by *kirakik*

Expand Down
8 changes: 8 additions & 0 deletions EZSwiftExtensions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
5A3292F41DC5BCC50078F7F3 /* CGPointTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3292F31DC5BCC50078F7F3 /* CGPointTests.swift */; };
5E9795001DDCC80D00E4C959 /* FileManagerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E9794FF1DDCC80D00E4C959 /* FileManagerExtension.swift */; };
5E9795011DDCC80D00E4C959 /* FileManagerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E9794FF1DDCC80D00E4C959 /* FileManagerExtension.swift */; };
5AB87AC71E50C205008A0B86 /* DataExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB87AC61E50C205008A0B86 /* DataExtensions.swift */; };
5AB87AC91E50C2F4008A0B86 /* DataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AB87AC81E50C2F4008A0B86 /* DataTests.swift */; };
7605D3121C81FC180046FAC3 /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7605D3021C81FBB80046FAC3 /* ArrayTests.swift */; };
7605D3131C81FC180046FAC3 /* BlockButtonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7605D3031C81FBB80046FAC3 /* BlockButtonTests.swift */; };
7605D3141C81FC180046FAC3 /* BoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7605D3041C81FBB80046FAC3 /* BoolTests.swift */; };
Expand Down Expand Up @@ -249,6 +251,8 @@
5A3292EF1DC5BA6F0078F7F3 /* CGPointExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGPointExtensions.swift; sourceTree = "<group>"; };
5A3292F31DC5BCC50078F7F3 /* CGPointTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGPointTests.swift; sourceTree = "<group>"; };
5E9794FF1DDCC80D00E4C959 /* FileManagerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileManagerExtension.swift; sourceTree = "<group>"; };
5AB87AC61E50C205008A0B86 /* DataExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataExtensions.swift; sourceTree = "<group>"; };
5AB87AC81E50C2F4008A0B86 /* DataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataTests.swift; sourceTree = "<group>"; };
7605D3021C81FBB80046FAC3 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTests.swift; sourceTree = "<group>"; };
7605D3031C81FBB80046FAC3 /* BlockButtonTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockButtonTests.swift; sourceTree = "<group>"; };
7605D3041C81FBB80046FAC3 /* BoolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoolTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -435,6 +439,7 @@
5A3292F31DC5BCC50078F7F3 /* CGPointTests.swift */,
E10A79651D6F65AF00735549 /* CGRectTests.swift */,
E10A79661D6F65AF00735549 /* CharacterTests.swift */,
5AB87AC81E50C2F4008A0B86 /* DataTests.swift */,
7605D3081C81FBB80046FAC3 /* DateTests.swift */,
7605D3061C81FBB80046FAC3 /* DictionaryTests.swift */,
E10A79671D6F65AF00735549 /* DoubleTests.swift */,
Expand Down Expand Up @@ -495,6 +500,7 @@
5A3292EF1DC5BA6F0078F7F3 /* CGPointExtensions.swift */,
B5DC87091C0ED34300972D0A /* CGRectExtensions.swift */,
E178781F1C867E9400BC05AA /* CharacterExtensions.swift */,
5AB87AC61E50C205008A0B86 /* DataExtensions.swift */,
E19AC0E81DCBA26500908905 /* DateExtensions.swift */,
B5DC870A1C0ED34300972D0A /* DictionaryExtensions.swift */,
31F868DA1C2B6E5E00542250 /* DoubleExtensions.swift */,
Expand Down Expand Up @@ -744,6 +750,7 @@
E15484E21CA2BCF0003B030E /* ErrorTypeExtensions.swift in Sources */,
31F868DB1C2B6E5E00542250 /* DoubleExtensions.swift in Sources */,
FADFAA631D9D8C2F00CF9F7A /* FloatingPointExtensions.swift in Sources */,
5AB87AC71E50C205008A0B86 /* DataExtensions.swift in Sources */,
E19AC0E61DCBA25100908905 /* BundleExtensions.swift in Sources */,
B5DC871C1C0ED34300972D0A /* ArrayExtensions.swift in Sources */,
E10A79461D6F506400735549 /* UIStoryboardExtensions.swift in Sources */,
Expand Down Expand Up @@ -848,6 +855,7 @@
E10A79AD1D6F65AF00735549 /* UISliderTests.swift in Sources */,
E10A79991D6F65AF00735549 /* UIApplicationTests.swift in Sources */,
7605D3151C81FC180046FAC3 /* CGFloatTests.swift in Sources */,
5AB87AC91E50C2F4008A0B86 /* DataTests.swift in Sources */,
E10A79A11D6F65AF00735549 /* UIColorTests.swift in Sources */,
7605D3181C81FC180046FAC3 /* DateTests.swift in Sources */,
E10A79AF1D6F65AF00735549 /* UIStoryboardTests.swift in Sources */,
Expand Down
41 changes: 41 additions & 0 deletions EZSwiftExtensionsTests/DataTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// DataTests.swift
// EZSwiftExtensions
//
// Created by Sanyal, Arunav on 2/12/17.
// Copyright © 2017 Goktug Yilmaz. All rights reserved.
//

import XCTest
import EZSwiftExtensions

class DataTests: XCTestCase {

override func setUp() {
super.setUp()
}

override func tearDown() {
super.tearDown()
}

func testNSAttributedStringSanityTest() {
let data = Data()
XCTAssertEqual(data.attributedString, NSAttributedString())
}

func testNSAttributedStringTest() {

// We can alternatively store the existing google.com contents on a file
// to stabilize this test case.
let url = URL(string:"http://www.google.com")
do {
let data = try Data(contentsOf: url!)
XCTAssertEqual(data.attributedString?.length, 217)

// TODO : Write additional tests on attrs, e.g. the font family
} catch _ {
XCTFail()
}
}
}
23 changes: 23 additions & 0 deletions Sources/DataExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// DataExtensions.swift
// EZSwiftExtensions
//
// Created by Sanyal, Arunav on 2/12/17.
// Copyright © 2017 Goktug Yilmaz. All rights reserved.
//

import Foundation

extension Data {

/// EZSE : Attributed string from data
/// Found it here : http://stackoverflow.com/questions/39248092/nsattributedstring-extension-in-swift-3
public var attributedString: NSAttributedString? {
do {
return try NSAttributedString(data: self, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
} catch let error {
NSLog(error.localizedDescription)
}
return nil
}
}