how to implement lazy loading of images in table view using swift

Old Solution: Since you doesn’t show any code. Here is the example for you. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // try to reuse cell let cell:CustomCell = tableView.dequeueReusableCellWithIdentifier(“DealCell”) as CustomCell // get the deal image let currentImage = deals[indexPath.row].imageID let unwrappedImage = currentImage var image = self.imageCache[unwrappedImage] let imageUrl = NSURL(string: … Read more

Which has faster performance indexesOfObjectsPassingTest or filteredArrayUsingPredicate?

The following tests (compiled in Release mode, executed on a Mac Pro) indicate that filteredArrayUsingPredicate is slower than indexesOfObjectsPassingTest if you use a “textual” predicate, but faster if you use block-based predicate. The fasted method in my test was a simple (fast-enumeration) loop that adds all matching objects to a mutable array. Results for filtering … Read more

iOS PNG Image rotated 90 degrees

For those that want a Swift solution, create an extension of UIImage and add the following method: func correctlyOrientedImage() -> UIImage { if self.imageOrientation == .up { return self } UIGraphicsBeginImageContextWithOptions(size, false, scale) draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) let normalizedImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return normalizedImage ?? self; }

[NSObject : AnyObject]?’ does not have a member named ‘subscript’ error in Xcode 6 beta 6

As mentioned in the Xcode 6 beta 6 release notes, a large number of Foundation APIs have been audited for optional conformance. These changes replace T! with either T? or T depending on whether the value can be null (or not) respectively. notification.userInfo is now an optional dictionary: class NSNotification : NSObject, NSCopying, NSCoding { … Read more

iOS – Scale and crop CMSampleBufferRef/CVImageBufferRef

If you use vimage you can work directly on the buffer data without converting it to any image format. outImg contains the cropped and scaled image data. The relation between outWidth and cropWidth sets the scaling. int cropX0, cropY0, cropHeight, cropWidth, outWidth, outHeight; CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(imageBuffer,0); void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer); size_t bytesPerRow = … Read more