Skip to content

Commit 928029d

Browse files
author
Sergey A. Novitsky
committed
Updated to Swift5 and fixed deprecation warnings.
1 parent b5e2229 commit 928029d

11 files changed

+41
-35
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# FFDataWrapper
22

3+
# Version 1.10
4+
- Swift version is changed to 5.
5+
- Xcode versions lower than 10.2 are no longer supported.
6+
- Fixed compiler deprecation warnings.
7+
38
## Version 1.9
49
- Changed the name of the framework/module on MacOS to avoid conflicts in the Xcode new build system.
510

FFDataWrapper.podspec

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'FFDataWrapper'
3-
spec.version = '1.9'
3+
spec.version = '1.10'
44
spec.ios.deployment_target = "9.3"
55
spec.osx.deployment_target = "10.10"
66
spec.license = { :type => 'MIT', :file => 'LICENSE' }
77
spec.summary = 'Wrapper for data or string objects with custom internal storage'
88
spec.homepage = 'https://github.com/flockoffiles/FFDataWrapper'
99
spec.author = 'Sergey Novitsky'
10-
spec.source = { :git => 'https://github.com/flockoffiles/FFDataWrapper.git', :tag => 'v' + String(spec.version) }
10+
# spec.source = { :git => 'https://github.com/flockoffiles/FFDataWrapper.git', :tag => 'v' + String(spec.version) }
11+
spec.source = { :git => 'https://github.com/flockoffiles/FFDataWrapper.git', :branch => 'swift5' }
1112
spec.source_files = 'FFDataWrapper/*.swift',
1213
spec.public_header_files = 'FFDataWrapper/*.h'
1314
spec.documentation_url = 'https://github.com/flockoffiles/FFDataWrapper/'
14-
spec.swift_version = '4.2'
15+
spec.swift_version = '5.0'
1516
# spec.dependency '', '~> 0.0.0'
1617
spec.preserve_paths = 'README.md', 'FFDataWrapperTests/*.swift'
17-
end
18+
end

FFDataWrapper.xcodeproj/project.pbxproj

+5-9
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
572AF0B120371C230094DA85 /* FFDataWrapperMacOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FFDataWrapperMacOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5757
572AF0B320371C230094DA85 /* FFDataWrapperMacOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FFDataWrapperMacOS.h; sourceTree = "<group>"; };
5858
572AF0B420371C230094DA85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
59+
5742D3A922895D20003EF87A /* FFDataWrapper.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = FFDataWrapper.podspec; sourceTree = "<group>"; };
5960
5766C516221BFB130063EA80 /* FFDataWrapper+Mapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FFDataWrapper+Mapping.swift"; sourceTree = "<group>"; };
6061
5766C518221C05F70063EA80 /* FFDataWrapper+InitializationWithInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FFDataWrapper+InitializationWithInfo.swift"; sourceTree = "<group>"; };
6162
57896109221B17E9001373CE /* FFDataWrapper+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FFDataWrapper+String.swift"; sourceTree = "<group>"; };
@@ -117,6 +118,7 @@
117118
A5063F791F73B29500CA4109 = {
118119
isa = PBXGroup;
119120
children = (
121+
5742D3A922895D20003EF87A /* FFDataWrapper.podspec */,
120122
570121B322579DB8001212E7 /* README.md */,
121123
570121B422579DCC001212E7 /* CHANGELOG.md */,
122124
A5063F851F73B29500CA4109 /* FFDataWrapper */,
@@ -257,7 +259,7 @@
257259
TargetAttributes = {
258260
572AF0B020371C230094DA85 = {
259261
CreatedOnToolsVersion = 9.2;
260-
LastSwiftMigration = 1010;
262+
LastSwiftMigration = 1020;
261263
ProvisioningStyle = Automatic;
262264
};
263265
A5063F821F73B29500CA4109 = {
@@ -397,7 +399,6 @@
397399
PRODUCT_NAME = FFDataWrapperMacOS;
398400
SDKROOT = macosx;
399401
SKIP_INSTALL = YES;
400-
SWIFT_VERSION = 4.2;
401402
};
402403
name = Debug;
403404
};
@@ -422,7 +423,6 @@
422423
PRODUCT_NAME = FFDataWrapperMacOS;
423424
SDKROOT = macosx;
424425
SKIP_INSTALL = YES;
425-
SWIFT_VERSION = 4.2;
426426
};
427427
name = Release;
428428
};
@@ -483,7 +483,7 @@
483483
SDKROOT = iphoneos;
484484
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
485485
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
486-
SWIFT_VERSION = 4.2;
486+
SWIFT_VERSION = 5.0;
487487
VERSIONING_SYSTEM = "apple-generic";
488488
VERSION_INFO_PREFIX = "";
489489
};
@@ -538,7 +538,7 @@
538538
MTL_ENABLE_DEBUG_INFO = NO;
539539
SDKROOT = iphoneos;
540540
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
541-
SWIFT_VERSION = 4.2;
541+
SWIFT_VERSION = 5.0;
542542
VALIDATE_PRODUCT = YES;
543543
VERSIONING_SYSTEM = "apple-generic";
544544
VERSION_INFO_PREFIX = "";
@@ -564,7 +564,6 @@
564564
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
565565
SKIP_INSTALL = YES;
566566
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
567-
SWIFT_VERSION = 4.2;
568567
TARGETED_DEVICE_FAMILY = "1,2";
569568
};
570569
name = Debug;
@@ -587,7 +586,6 @@
587586
PRODUCT_BUNDLE_IDENTIFIER = com.flockoffiles.FFDataWrapper;
588587
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
589588
SKIP_INSTALL = YES;
590-
SWIFT_VERSION = 4.2;
591589
TARGETED_DEVICE_FAMILY = "1,2";
592590
};
593591
name = Release;
@@ -602,7 +600,6 @@
602600
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
603601
PRODUCT_BUNDLE_IDENTIFIER = com.flockoffiles.FFDataWrapperTests;
604602
PRODUCT_NAME = "$(TARGET_NAME)";
605-
SWIFT_VERSION = 4.2;
606603
TARGETED_DEVICE_FAMILY = "1,2";
607604
};
608605
name = Debug;
@@ -617,7 +614,6 @@
617614
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
618615
PRODUCT_BUNDLE_IDENTIFIER = com.flockoffiles.FFDataWrapperTests;
619616
PRODUCT_NAME = "$(TARGET_NAME)";
620-
SWIFT_VERSION = 4.2;
621617
TARGETED_DEVICE_FAMILY = "1,2";
622618
};
623619
name = Release;

FFDataWrapper/FFDataWrapper+Data.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public extension FFDataWrapper {
2525

2626
if (data.count > 0) {
2727
// Encode the data
28-
data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) -> Void in
28+
data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> Void in
2929
let initialEncoder = encode ? unwrappedCoders.encoder : FFDataWrapperEncoders.identity.coders.encoder
30-
initialEncoder(UnsafeBufferPointer(start: bytes, count: data.count),
30+
initialEncoder(UnsafeBufferPointer(start: bytes.baseAddress!.assumingMemoryBound(to: UInt8.self), count: data.count),
3131
UnsafeMutableBufferPointer(start: self.dataRef.dataBuffer.baseAddress!, count: self.dataRef.dataBuffer.count))
3232
}
3333
}
@@ -58,9 +58,9 @@ public extension FFDataWrapper {
5858

5959
if (data.count > 0) {
6060
// Encode the data
61-
data.withUnsafeBytes { (bytes: UnsafePointer<UInt8>) in
61+
data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) in
6262
let initialEncoder = encode ? unwrappedCoders.encoder : FFDataWrapperEncoders.infoIdentityFunction()
63-
initialEncoder(UnsafeBufferPointer(start: bytes, count: data.count),
63+
initialEncoder(UnsafeBufferPointer(start: bytes.baseAddress!.assumingMemoryBound(to: UInt8.self), count: data.count),
6464
UnsafeMutableBufferPointer(start: self.dataRef.dataBuffer.baseAddress!, count: self.dataRef.dataBuffer.count),
6565
info)
6666
}

FFDataWrapper/FFDataWrapper+Initialization.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ extension FFDataWrapper {
112112
encode: Bool = true,
113113
initializer: (UnsafeMutableBufferPointer<UInt8>) -> Void) {
114114
let coders: FFDataWrapper.Coders? = FFDataWrapper.Coders(coder, coder)
115-
try! self.init(length: length, coders: coders, encode: encode, initializer: initializer)
115+
self.init(length: length, coders: coders, encode: encode, initializer: initializer)
116116
}
117117

118118
/// Create a wrapper with the given maximum capacity (in bytes).
@@ -176,7 +176,7 @@ extension FFDataWrapper {
176176
encode: Bool = true,
177177
initializer: (UnsafeMutableBufferPointer<UInt8>, UnsafeMutablePointer<Int>) -> Void) {
178178
let coders = FFDataWrapper.Coders(coder, coder)
179-
try! self.init(capacity: capacity, coders: coders, encode: encode, initializer: initializer)
179+
self.init(capacity: capacity, coders: coders, encode: encode, initializer: initializer)
180180
}
181181

182182
}

FFDataWrapper/FFDataWrapper+InitializationWithInfo.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extension FFDataWrapper {
101101
encode: Bool = true,
102102
initializer: (UnsafeMutableBufferPointer<UInt8>) -> Void) {
103103
let coders: FFDataWrapper.InfoCoders? = FFDataWrapper.InfoCoders(infoCoder, infoCoder)
104-
try! self.init(length: length, infoCoders: coders, info: info, encode: encode, initializer: initializer)
104+
self.init(length: length, infoCoders: coders, info: info, encode: encode, initializer: initializer)
105105
}
106106

107107
/// Create a wrapper with the given maximum capacity (in bytes).
@@ -169,6 +169,6 @@ extension FFDataWrapper {
169169
encode: Bool = true,
170170
initializer: (UnsafeMutableBufferPointer<UInt8>, UnsafeMutablePointer<Int>) -> Void) {
171171
let coders = FFDataWrapper.InfoCoders(infoCoder, infoCoder)
172-
try! self.init(capacity: capacity, infoCoders: coders, encode: encode, initializer: initializer)
172+
self.init(capacity: capacity, infoCoders: coders, encode: encode, initializer: initializer)
173173
}
174174
}

FFDataWrapper/FFDataWrapper+Mapping.swift

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ extension FFDataWrapper {
1919
public func mapData<ResultType>(_ block: (inout Data) throws -> ResultType) rethrows -> ResultType {
2020
var decodedData = Data(repeating:0, count: dataRef.dataBuffer.count)
2121

22-
let count = decodedData.withUnsafeMutableBytes({ (destPtr: UnsafeMutablePointer<UInt8>) -> Int in
22+
let count = decodedData.withUnsafeMutableBytes({ (destMutableRawBufferPtr: UnsafeMutableRawBufferPointer) -> Int in
2323
switch self.storedCoders {
2424
case .coders(_, let decoder):
2525
decoder(UnsafeBufferPointer(start: self.dataRef.dataBuffer.baseAddress!, count: dataRef.dataBuffer.count),
26-
UnsafeMutableBufferPointer(start: destPtr, count: dataRef.dataBuffer.count))
26+
UnsafeMutableBufferPointer(start: destMutableRawBufferPtr.baseAddress!.assumingMemoryBound(to: UInt8.self),
27+
count: dataRef.dataBuffer.count))
2728
return dataRef.dataBuffer.count
2829
case .infoCoders(_, let decoder):
2930
decoder(UnsafeBufferPointer(start: self.dataRef.dataBuffer.baseAddress!, count: dataRef.dataBuffer.count),
30-
UnsafeMutableBufferPointer(start: destPtr, count: dataRef.dataBuffer.count), nil)
31+
UnsafeMutableBufferPointer(start: destMutableRawBufferPtr.baseAddress!.assumingMemoryBound(to: UInt8.self),
32+
count: dataRef.dataBuffer.count), nil)
3133
return dataRef.dataBuffer.count
3234
}
3335

@@ -54,14 +56,16 @@ extension FFDataWrapper {
5456
public func mapData<ResultType>(info: Any?, block: (inout Data) throws -> ResultType) rethrows -> ResultType {
5557
var decodedData = Data(repeating:0, count: dataRef.dataBuffer.count)
5658

57-
decodedData.withUnsafeMutableBytes({ (destPtr: UnsafeMutablePointer<UInt8>) -> Void in
59+
decodedData.withUnsafeMutableBytes({ (destMutableRawBufferPtr: UnsafeMutableRawBufferPointer) -> Void in
5860
switch self.storedCoders {
5961
case .coders(_, let decoder):
6062
decoder(UnsafeBufferPointer(start: self.dataRef.dataBuffer.baseAddress!, count: dataRef.dataBuffer.count),
61-
UnsafeMutableBufferPointer(start: destPtr, count: dataRef.dataBuffer.count))
63+
UnsafeMutableBufferPointer(start: destMutableRawBufferPtr.baseAddress!.assumingMemoryBound(to: UInt8.self),
64+
count: dataRef.dataBuffer.count))
6265
case .infoCoders(_, let decoder):
6366
decoder(UnsafeBufferPointer(start: self.dataRef.dataBuffer.baseAddress!, count: dataRef.dataBuffer.count),
64-
UnsafeMutableBufferPointer(start: destPtr, count: dataRef.dataBuffer.count), info)
67+
UnsafeMutableBufferPointer(start: destMutableRawBufferPtr.baseAddress!.assumingMemoryBound(to: UInt8.self),
68+
count: dataRef.dataBuffer.count), info)
6569
}
6670
})
6771
let result = try block(&decodedData)

FFDataWrapper/FFDataWrapperEncoders.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public enum FFDataWrapperEncoders {
2424
case .xorWithRandomVectorOfLength(let length):
2525
var vector = Data(count: length)
2626
let _ = vector.withUnsafeMutableBytes {
27-
SecRandomCopyBytes(kSecRandomDefault, length, $0)
27+
return SecRandomCopyBytes(kSecRandomDefault, $0.count, $0.baseAddress!)
2828
}
2929

3030
return (encoder: FFDataWrapperEncoders.xorWithVector(vector), decoder: FFDataWrapperEncoders.xorWithVector(vector))
@@ -40,7 +40,7 @@ public enum FFDataWrapperEncoders {
4040
case .xorWithRandomVectorOfLength(let length):
4141
var vector = Data(count: length)
4242
let _ = vector.withUnsafeMutableBytes {
43-
SecRandomCopyBytes(kSecRandomDefault, length, $0)
43+
return SecRandomCopyBytes(kSecRandomDefault, $0.count, $0.baseAddress!)
4444
}
4545

4646
return (encoder: FFDataWrapperEncoders.infoXorWithVector(vector), decoder: FFDataWrapperEncoders.infoXorWithVector(vector))
@@ -124,7 +124,7 @@ public extension FFDataWrapperEncoders {
124124

125125
public extension Array where Element == UInt8 {
126126
func coders(_ coder: (Data) -> FFDataWrapper.Coder) -> (FFDataWrapper.Coder, FFDataWrapper.Coder) {
127-
let data = Data(bytes: self)
127+
let data = Data(self)
128128
return (coder(data), coder(data))
129129
}
130130
}

FFDataWrapper/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.9</string>
18+
<string>1.10</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

FFDataWrapperMacOS/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.9</string>
18+
<string>1.10</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSHumanReadableCopyright</key>

FFDataWrapperTests/FFDataWrapperTests.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ class FFDataWrapperTests: XCTestCase
122122
var copiedBacking = Data()
123123

124124
let bytes: UnsafePointer<UInt8> = dataWrapper.mapData({ (data: inout Data) -> UnsafePointer<UInt8> in
125-
return data.withUnsafeBytes({ (ptr: UnsafePointer<UInt8>) -> UnsafePointer<UInt8> in
126-
copiedBacking = Data(bytes: ptr, count: data.count)
127-
return ptr
125+
return data.withUnsafeBytes({ (ptr: UnsafeRawBufferPointer) -> UnsafePointer<UInt8> in
126+
copiedBacking = Data(bytes: ptr.baseAddress!.assumingMemoryBound(to: UInt8.self), count: data.count)
127+
return ptr.baseAddress!.assumingMemoryBound(to: UInt8.self)
128128
})
129129
})
130130

0 commit comments

Comments
 (0)