Kodeco Forums

Core Image Tutorial: Getting Started

Learn the basics of cool image filtering effects with Core Image and Swift.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2305-core-image-tutorial-getting-started

Awesome tutorial. Can you guys do one on videos? How would one go on to filter recorded video files?

I’m sure it is a wonderful tutorial as all others might be… Only problem, is that ALL swift example code is NOT working when xcode asks to convert to new swift language…

I would expect from a site like this that you at least UPDATE the example code so that it is useable…

VERY disappointed !

This article looked relevant to what I am trying to do. Hence reposting here:

I would love for this tutorial to be updated to Swift 3.

1 Like

If you create your own project and enter all the code, then Xcode will let you know what has to be changed for Swift 3. It’s a good learning experience, in my opinion. The most challenging part was saving the photo. The AssetsLibrary framework is deprecated and you are supposed to use the Photos framework. It lets you create a custom album with the name you want to save the images to.

Here is my code for saving a photo. Make sure you import Photos.

     PHPhotoLibrary.shared().performChanges({
     let creationRequest = PHAssetChangeRequest.creationRequestForAsset(from: imageToSave)
     var addAssetRequest = PHAssetCollectionChangeRequest()
     
     let predicate = NSPredicate(format: "%K == %@", "localizedTitle", "Core Image Fun")
     let options = PHFetchOptions()
     options.predicate = predicate
     
     if let album = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .albumRegular, options: options).firstObject {
        addAssetRequest = PHAssetCollectionChangeRequest(for: album)!
        print("Found album!!!")
     } else {
        addAssetRequest = PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: "Core Image Fun")
        print("Creating Album!!!")
     }
     
     addAssetRequest.addAssets([creationRequest.placeholderForCreatedAsset!] as NSArray)
  }, completionHandler: { success, error in
     if !success {
        print("Unsuccessful save: \(error?.localizedDescription)")
     } else {
        print("SAVED!")
     }
  })

Here is a link to the documentation. Apple Developer Documentation

I agree that this code needs to be updated. I wouldn’t need a tutorial if I understood what I needed to change for it to work with the latest update.

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]