IKerby- IKerby- - 2 months ago
191 0

I am getting this error "Thread 1: Signal SIGABRT". Please can someone help me fixing this.

Swift

Swift - Thread 1: Signal SIGABRT

AppDelegate

//
//  AppDelegate.swift
//  Photo Libary1
//
//  Created by julien lamparter on 11.09.16.
//  Copyright © 2016 julien lamparter. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

    func applicationWillResignActive(application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(application: UIApplication) {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}




ViewController

//
//  ViewController.swift
//  Photo Libary1
//
//  Created by julien lamparter on 11.09.16.
//  Copyright © 2016 julien lamparter. All rights reserved.
//

import UIKit
import Photos

class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
    
    var imageArray = [UIImage]()
    
    
    override func viewDidLoad() {
        grabPhotos()
    }
    
    
    
    func grabPhotos(){
        
        let imgManager = PHImageManager.defaultManager()
        
        
        let requestOptions = PHImageRequestOptions()
        requestOptions.synchronous = true
        requestOptions.deliveryMode = .HighQualityFormat
        
        let fetchOptions = PHFetchOptions()
        fetchOptions.sortDescriptors = [NSSortDescriptor(key:"CreationDate" , ascending: false)]
        
        if let fetchResult : PHFetchResult = PHAsset.fetchAssetsWithMediaType(.Image, options: fetchOptions){
            
            if fetchResult.count > 0 {
                
                for i in 0..<fetchResult.count{
                    
                    imgManager.requestImageForAsset(fetchResult.objectAtIndex(i) as! PHAsset, targetSize: CGSize(width: 200, height: 200), contentMode: .AspectFill, options: requestOptions, resultHandler: {
                        
                        image, error in
                        
                        self.imageArray.append(image!)
                        
                    })
                }
                
            }
            else{
                
                print("You have got not photos!")
                self.collectionView?.reloadData()
            }
        }
    }

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return imageArray.count
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath)
        
        let imageView = cell.viewWithTag(1) as! UIImageView
        
        imageView.image = imageArray[indexPath.row]
        
        return cell
        
        
        
    }
    
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        
        let width = collectionView.frame.width / 3 - 1
        
        return CGSize(width: width, height: width)
    }
    
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
        return 1.0
    }
    
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
        return 1.0
    }
    
    
}




Terminal

2016-09-11 14:47:49.308 Photo Libary1[8341:220931] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported sort descriptor in fetch options: (CreationDate, descending, compare:)'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000102978d85 __exceptionPreprocess + 165
	1   libobjc.A.dylib                     0x0000000104f32deb objc_exception_throw + 48
	2   Photos                              0x00000001038c3aec __52+[PHQuery _transformedSortDescriptors:forFetchType:]_block_invoke + 495
	3   CoreFoundation                      0x00000001028c9374 __NSArrayEnumerate + 596
	4   Photos                              0x00000001038c38d9 +[PHQuery _transformedSortDescriptors:forFetchType:] + 196
	5   Photos                              0x00000001038c3fa7 -[PHQuery _effectiveSortDescriptors] + 219
	6   Photos                              0x00000001038c3c7f -[PHQuery _createFetchRequestIncludingBasePredicate:] + 368
	7   Photos                              0x00000001038c45ec -[PHQuery fetchRequest] + 44
	8   Photos                              0x00000001038d935c -[PHFetchResult initWithQuery:oids:registerIfNeeded:usingManagedObjectContext:] + 175
	9   Photos                              0x00000001038d9285 -[PHFetchResult initWithQuery:] + 94
	10  Photos                              0x00000001038c628e -[PHQuery executeQuery] + 50
	11  Photos                              0x00000001038aa53c __44+[PHAsset fetchAssetsWithMediaType:options:]_block_invoke + 68
	12  Photos                              0x00000001038c289b +[PHObject authorizationAwareFetchResultWithOptions:fetchBlock:] + 75
	13  Photos                              0x00000001038aa4f2 +[PHAsset fetchAssetsWithMediaType:options:] + 89
	14  Photo Libary1                       0x000000010278ea25 _TFC13Photo_Libary114ViewController10grabPhotosfT_T_ + 565
	15  Photo Libary1                       0x000000010278e79c _TFC13Photo_Libary114ViewController11viewDidLoadfT_T_ + 28
	16  Photo Libary1                       0x000000010278e7d2 _TToFC13Photo_Libary114ViewController11viewDidLoadfT_T_ + 34
	17  UIKit                               0x0000000103b51984 -[UIViewController loadViewIfRequired] + 1198
	18  UIKit                               0x0000000103b51cd3 -[UIViewController view] + 27
	19  UIKit                               0x0000000103a27fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61
	20  UIKit                               0x0000000103a2869d -[UIWindow _setHidden:forced:] + 282
	21  UIKit                               0x0000000103a3a180 -[UIWindow makeKeyAndVisible] + 42
	22  UIKit                               0x00000001039aeed9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
	23  UIKit                               0x00000001039b5568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
	24  UIKit                               0x00000001039b2714 -[UIApplication workspaceDidEndTransaction:] + 188
	25  FrontBoardServices                  0x000000010b2f08c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
	26  FrontBoardServices                  0x000000010b2f0741 -[FBSSerialQueue _performNext] + 178
	27  FrontBoardServices                  0x000000010b2f0aca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
	28  CoreFoundation                      0x000000010289e301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
	29  CoreFoundation                      0x000000010289422c __CFRunLoopDoSources0 + 556
	30  CoreFoundation                      0x00000001028936e3 __CFRunLoopRun + 867
	31  CoreFoundation                      0x00000001028930f8 CFRunLoopRunSpecific + 488
	32  UIKit                               0x00000001039b1f21 -[UIApplication _run] + 402
	33  UIKit                               0x00000001039b6f09 UIApplicationMain + 171
	34  Photo Libary1                       0x000000010278e452 main + 114
	35  libdyld.dylib                       0x0000000105a3192d start + 1
	36  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)