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

Swift3 migration #2

Open
wants to merge 32 commits into
base: developer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5b89950
After auto-conversion
Oct 6, 2016
7c1524d
Swift3 migration. Project compiles. But plot not drawing.
Oct 10, 2016
7a00191
Swift3. Migration completed.
Oct 10, 2016
bc99b0a
Rip off pointer conversion through nsdata. Speed up waveform rendering
Oct 10, 2016
d1618d7
Merged developer branch
Oct 10, 2016
ad61c84
Semaphore for buffer to preven concurent read/write access
Nov 1, 2016
a56a572
Waweform scale-pan crash fixed
Nov 11, 2016
cc149d1
Max scale limited to one second on diagram
Nov 14, 2016
5e16e88
Revert "Waweform scale-pan crash fixed"
Nov 14, 2016
fea0f29
Cursor image changed
Nov 24, 2016
5e945fa
Added resources to podspec
Nov 24, 2016
0ccb52e
Podspec file updated
Nov 24, 2016
83988be
Icon play slider added
Nov 24, 2016
6bfc934
Podspec adjusted
Nov 24, 2016
c975ccb
Images changes to png
Nov 24, 2016
da12534
Images added to project
Nov 24, 2016
8a3c8cb
Images moved to resources folder
Nov 24, 2016
2b9a095
Project updated according to images relocation
Nov 24, 2016
bbbefa3
Images renamed
Nov 24, 2016
4c1bec8
Images location in project fixed
Nov 24, 2016
4114727
Fixed playback position view rules for cursor position
Nov 24, 2016
62e002e
Slider size adjusted for 2x resolution
Nov 24, 2016
aad6a00
Sliders added to waweform selection
Nov 25, 2016
d8242ca
Selection view ux updated. Sliders added. Tap to select removed.
Nov 28, 2016
d987ebd
Selection view fixes
Nov 29, 2016
df9db6b
Vesrion bump
Nov 29, 2016
54eb083
Pod version 3.1.0 bump
Nov 29, 2016
b170c5d
Added method for stop loading
Dec 2, 2016
08b3819
Cancel method for AudioSamplesReader implemented
Dec 2, 2016
7d986d4
Selection on zoom fixed
Dec 8, 2016
1b5022c
Restarting sound loading after app enters foreground
Dec 12, 2016
267bad1
Fix for cursor position
Dec 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Example/SRC/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -30,6 +40,16 @@
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
Expand Down
12 changes: 6 additions & 6 deletions Example/SRC/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -13,10 +14,9 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
78 changes: 36 additions & 42 deletions Example/SRC/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Example/SRC/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>3.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>4</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
Expand Down
45 changes: 24 additions & 21 deletions Example/SRC/VideoCollectionReusableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VideoCollectionReusableView: UICollectionReusableView {
}
}

let date = NSDateFormatter.localizedStringFromDate(collection.startDate!, dateStyle:.LongStyle, timeStyle:.NoStyle)
let date = DateFormatter.localizedString(from: collection.startDate!, dateStyle:.long, timeStyle:.none)

if self.titleLabel.text != nil {
self.dateLabel.text = date
Expand All @@ -76,30 +76,33 @@ class VideoCollectionReusableView: UICollectionReusableView {

if (self.subtitleLabel.text?.characters.count == 0) {

self.titleLabel.frame = CGRectMake(horizontalBordersOffset,
titleLabelTopOffsetWithNoSubtitle,
CGRectGetWidth(self.bounds) - dateLabelWidth,
CGRectGetHeight(self.bounds) - titleLabelTopOffsetWithNoSubtitle)
self.titleLabel.frame = CGRect(origin: CGPoint(x: horizontalBordersOffset,
y: titleLabelTopOffsetWithNoSubtitle ),
size: CGSize(width: self.bounds.width - dateLabelWidth,
height: self.bounds.height - titleLabelTopOffsetWithNoSubtitle ))



self.dateLabel.frame = CGRect( origin: CGPoint(x: self.bounds.width - dateLabelWidth - horizontalBordersOffset,
y: 0 + titleLabelTopOffsetWithNoSubtitle ),
size: CGSize(width: dateLabelWidth,
height: self.bounds.height - titleLabelTopOffsetWithNoSubtitle ))

self.dateLabel.frame = CGRectMake(CGRectGetWidth(self.bounds) - dateLabelWidth - horizontalBordersOffset,
0 + titleLabelTopOffsetWithNoSubtitle,
dateLabelWidth,
CGRectGetHeight(self.bounds) - titleLabelTopOffsetWithNoSubtitle)
} else {
self.titleLabel.frame = CGRectMake(horizontalBordersOffset,
titleLabelTopOffset,
CGRectGetWidth(self.bounds) - dateLabelWidth - 2 * horizontalBordersOffset,
CGRectGetHeight(self.titleLabel.bounds))
self.titleLabel.frame = CGRect( origin: CGPoint(x: horizontalBordersOffset,
y: titleLabelTopOffset ),
size: CGSize(width: self.bounds.width - dateLabelWidth - 2 * horizontalBordersOffset,
height: self.titleLabel.bounds.height ))

self.subtitleLabel.frame = CGRectMake(horizontalBordersOffset,
CGRectGetHeight(self.bounds) - subtitleLabelBottomOffset - CGRectGetHeight(self.subtitleLabel.bounds),
CGRectGetWidth(self.bounds) - dateLabelWidth - 2 * horizontalBordersOffset,
CGRectGetHeight(self.subtitleLabel.bounds))
self.subtitleLabel.frame = CGRect( origin: CGPoint(x: horizontalBordersOffset,
y: self.bounds.height - subtitleLabelBottomOffset - self.subtitleLabel.bounds.height ),
size: CGSize(width: self.bounds.width - dateLabelWidth - 2 * horizontalBordersOffset,
height: self.subtitleLabel.bounds.height))

self.dateLabel.frame = CGRectMake(CGRectGetWidth(self.bounds) - dateLabelWidth - horizontalBordersOffset,
titleLabelTopOffset,
dateLabelWidth,
CGRectGetHeight(self.dateLabel.bounds) )
self.dateLabel.frame = CGRect( origin: CGPoint(x: self.bounds.width - dateLabelWidth - horizontalBordersOffset,
y: titleLabelTopOffset ),
size: CGSize(width: dateLabelWidth,
height: self.dateLabel.bounds.height ))
}
}
}
14 changes: 7 additions & 7 deletions Example/SRC/VideoCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ class VideoCollectionViewCell: UICollectionViewCell {
guard let videoSource = videoSource else {
return
}
self.timeLabel.text = self.stringWithTime(videoSource.duration)
self.timeLabel.text = self.stringWithTime(time: videoSource.duration)
self.timeLabelContainer.layer.cornerRadius = self.timeLabelContainer.bounds.size.height/2;


imageManager.requestImageForAsset(videoSource, targetSize:self.bounds.size, contentMode:.AspectFill, options:nil, resultHandler: {result, _ in
imageManager.requestImage(for: videoSource, targetSize:self.bounds.size, contentMode:.aspectFill, options:nil, resultHandler: {result, _ in
self.imageView.image = result;
})
}
}

func stringWithTime(time:NSTimeInterval) -> String {
var seconds = time;
func stringWithTime(time:TimeInterval) -> String {
var seconds = time.int;
var minutes = seconds/60;
seconds = seconds%60;
let hours = minutes/60;
minutes = minutes%60;

if hours > 0 {
return String(format: "%d:%02d:%02d", Int(hours), Int(minutes), Int(seconds));
return String(format: "%d:%d:%d", hours, minutes, seconds);
} else if minutes > 0 {
return String(format:"%d:%02d", Int(minutes), Int(seconds));
return String(format:"%d:%d", minutes, seconds);
} else {
return String(format:"0:%02d", Int(seconds));
return String(format:"0:%d", seconds);
}
}
}
75 changes: 37 additions & 38 deletions Example/SRC/VideoCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import Photos
@objc
class VideoCollectionViewController: UICollectionViewController {

var assetsFetchResults: [PHFetchResult] = []
var assetsFetchResults: [PHFetchResult] = [PHFetchResult<AnyObject>]()
var moments: [PHAssetCollection] = []

var userAlbumsFetchPredicate = NSPredicate(format: "estimatedAssetCount > 0")
var userAlbumsFetchSortDescriptors = [NSSortDescriptor(key: "startDate", ascending: false)]
var inAlbumItemsFetchPredicate = NSPredicate(format: "mediaType == %d", PHAssetMediaType.Video.rawValue)
var inAlbumItemsFetchPredicate = NSPredicate(format: "mediaType == %d", PHAssetMediaType.video.rawValue)

var selectedSnapshotView: UIView?

private struct Constants {
fileprivate struct Constants {
static let collectionViewCellReuseId = "video_collection_view_cell"
static let collectionHeaderReuseId = "video_collection_view_header"
static let collectionFooterReuseId = "FooterView"
Expand All @@ -44,11 +44,11 @@ class VideoCollectionViewController: UICollectionViewController {
// MARK: - Constuctor/Destructor
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
PHPhotoLibrary.sharedPhotoLibrary().registerChangeObserver(self)
PHPhotoLibrary.shared().register(self)
}

deinit{
PHPhotoLibrary.sharedPhotoLibrary().unregisterChangeObserver(self)
PHPhotoLibrary.shared().unregisterChangeObserver(self)
}

// MARK: - View Controller Lifetime
Expand All @@ -57,10 +57,10 @@ class VideoCollectionViewController: UICollectionViewController {

// Hide nav bar bottom line
let navBarHairlineImageView: UIImageView? = navigationController?.barHairlineImageView()
navBarHairlineImageView?.hidden = true;
navBarHairlineImageView?.isHidden = true;
}

override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
clearApplicationTmpDirectory()

Expand All @@ -74,17 +74,17 @@ class VideoCollectionViewController: UICollectionViewController {

// MARK: - UICollectionViewDataSource
extension VideoCollectionViewController {
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return assetsFetchResults.count
}

override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return assetsFetchResults[section].count
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(Constants.collectionViewCellReuseId, forIndexPath:indexPath)
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Constants.collectionViewCellReuseId, for:indexPath)

if let cell = cell as? VideoCollectionViewCell,
let asset = self.assetsFetchResults[indexPath.section][indexPath.row] as? PHAsset {
Expand All @@ -96,14 +96,14 @@ extension VideoCollectionViewController {
return cell
}

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

let reuseId = Constants.collectionSupplementaryElementReuseIdForKind(kind)
let reusableView = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: reuseId, forIndexPath: indexPath)
let reuseId = Constants.collectionSupplementaryElementReuseIdForKind(kind: kind)
let reusableView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: reuseId, for: indexPath)

switch (kind, reusableView) {
case (UICollectionElementKindSectionHeader, let headerView as VideoCollectionReusableView):
headerView.configureWithCollection(self.moments[indexPath.section])
headerView.configureWithCollection(collection: self.moments[indexPath.section])
case (UICollectionElementKindSectionFooter, _): ()
default:
fatalError()
Expand All @@ -119,20 +119,20 @@ extension VideoCollectionViewController: UICollectionViewDelegateFlowLayout {
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

let count = floor(self.view.bounds.width/Constants.preview_width);
let width = CGRectGetWidth(self.view.bounds)/count;
return CGSizeMake(width, Constants.preview_height);
let width = self.view.bounds.width/count;
return CGSize(width: width,height: Constants.preview_height);
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsetsZero
return .zero
}
}

// MARK: - Navigation/Transition
extension VideoCollectionViewController {

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let controller = segue.destinationViewController as! ViewController
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let controller = segue.destination as! ViewController
let cell = sender as! VideoCollectionViewCell
controller.phAsset = cell.videoSource
}
Expand All @@ -143,30 +143,28 @@ extension VideoCollectionViewController {
extension VideoCollectionViewController {

func updateAssetsFetchResultsAndMoments() {
var assets = [PHFetchResult]()
var assets = [PHFetchResult<AnyObject>]()
var moments = [PHAssetCollection]()

let userAlbumsFetchOptions = PHFetchOptions()
userAlbumsFetchOptions.predicate = userAlbumsFetchPredicate
userAlbumsFetchOptions.sortDescriptors = userAlbumsFetchSortDescriptors

let userAlbumsFetchResult = PHAssetCollection.fetchMomentsWithOptions(userAlbumsFetchOptions)
let userAlbumsFetchResult = PHAssetCollection.fetchMoments(with: userAlbumsFetchOptions)

let inAlbumItemsFetchOptions = PHFetchOptions()
inAlbumItemsFetchOptions.predicate = inAlbumItemsFetchPredicate

userAlbumsFetchResult.enumerateObjectsUsingBlock { (collection, _, _) -> Void in
guard let collection = collection as? PHAssetCollection else {
return
}

userAlbumsFetchResult.enumerateObjects ({ (collection, _, _) -> Void in

let assetsFetchResult = PHAsset.fetchAssetsInAssetCollection(collection, options: inAlbumItemsFetchOptions)
let assetsFetchResult = PHAsset.fetchAssets(in: collection, options: inAlbumItemsFetchOptions)

if assetsFetchResult.count > 0 {
assets.append(assetsFetchResult)
assets.append(assetsFetchResult as! PHFetchResult<AnyObject>)
moments.append(collection)
}
}
})

self.moments = moments
self.assetsFetchResults = assets
Expand All @@ -176,20 +174,21 @@ extension VideoCollectionViewController {

// MARK: - View Controller Auto Rotation
extension VideoCollectionViewController {
override func shouldAutorotate() -> Bool {

override var shouldAutorotate: Bool {
return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
}


// MARK: - PHPhotoLibraryChangeObserver
extension VideoCollectionViewController: PHPhotoLibraryChangeObserver {
func photoLibraryDidChange(changeInstance: PHChange) {
dispatch_async(dispatch_get_main_queue()) { () -> Void in
func photoLibraryDidChange(_ changeInstance: PHChange) {
DispatchQueue.main.async { () -> Void in
self.updateAssetsFetchResultsAndMoments()
self.collectionView?.reloadData()
}
Expand All @@ -208,9 +207,9 @@ extension UINavigationController {

// MARK: - UIView ex
extension UIView {
func findSubview<T: UIView>(predicate: (T) -> (Bool)) -> T? {
func findSubview<T: UIView>(_ predicate: (T) -> (Bool)) -> T? {

if let self_ = self as? T where predicate(self_) {
if let self_ = self as? T , predicate(self_) {
return self_
}

Expand All @@ -226,10 +225,10 @@ extension UIView {
// MARK: - Utility
func clearApplicationTmpDirectory() {
do {
let tmpDirectoryContent = try NSFileManager.defaultManager().contentsOfDirectoryAtPath(NSTemporaryDirectory())
let tmpDirectoryContent = try FileManager.default.contentsOfDirectory(atPath: NSTemporaryDirectory())
for file in tmpDirectoryContent {
let filePath = NSTemporaryDirectory() + file
try NSFileManager.defaultManager().removeItemAtPath(filePath)
try FileManager.default.removeItem(atPath: filePath)
}
} catch (let error) {
print("\(#function), catched error:\(error)")
Expand Down
Loading