Skip to content

Instantly share code, notes, and snippets.

@MickaelCruzDB
Created June 29, 2015 11:14
Show Gist options
  • Save MickaelCruzDB/952f7423d3e12345c5c5 to your computer and use it in GitHub Desktop.
Save MickaelCruzDB/952f7423d3e12345c5c5 to your computer and use it in GitHub Desktop.
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var context:NSManagedObjectContext = appDel.managedObjectContext!
// Initialize the reusable Collection View Cell with our custom class
icon = PortfolioView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ProductCell
iconiPhone47 = PortfolioViewiPhone47.dequeueReusableCellWithReuseIdentifier(reuseIdentifieriPhone47, forIndexPath: indexPath) as! ProductCelliPhone47
var photoName = String()
// Initialize the photoName variable with an item in the searchResults array or an item in the imageFileNames array
if isSearchOn == true && !searchResults.isEmpty {
photoName = searchResults[indexPath.item]
} else {
photoName = imageFileNames[indexPath.item]
}
// Configure the collection view cell
icon.imageView.image = UIImage(named: photoName)
iconiPhone47.imageView.image = UIImage(named: photoName)
var stringArray: Array = photoName.componentsSeparatedByString(".")
if photoName == "Wastegate Actuator.png" {
var request = NSFetchRequest(entityName: "WastegateActuator")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
if photoName == "Electric Compression Bypass Valve.png" {
var request = NSFetchRequest(entityName: "ElectricalCompressorBypass")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString2 = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString2
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString2
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
if photoName == "Turbocharger Aluminium.png" {
var request = NSFetchRequest(entityName: "TurbochargerAluminum")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString2 = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString2
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString2
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
if photoName == "Linear Exhaust Control Valve.png" {
var request = NSFetchRequest(entityName: "LinearExhaustControlValve")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString2 = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString2
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString2
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
if photoName == "Gasoline ECU.png" {
var request = NSFetchRequest(entityName: "GasolineECU")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
if photoName == "GHP 25.png" {
var request = NSFetchRequest(entityName: "GHP25")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
if photoName == "DI Injector XL31.png" {
var request = NSFetchRequest(entityName: "DIInjector")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
if photoName == "DHP 11.png" {
var request = NSFetchRequest(entityName: "DHP11")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
if photoName == "Diesel ECU.png" {
var request = NSFetchRequest(entityName: "DieselECU")
var results = context.executeFetchRequest(request, error: nil)
if (results?.count > 0) {
for eachResult: AnyObject in results! {
if let storedTitle = eachResult.valueForKey("title") as? String {
if storedTitle == "nil" {
context.deleteObject(eachResult as! NSManagedObject)
}
let encodedData = storedTitle.dataUsingEncoding(NSUTF8StringEncoding)!
let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding]
let attributedString = NSAttributedString(data: encodedData, options: attributedOptions as [NSObject : AnyObject], documentAttributes: nil, error: nil)
//let decodedString = attributedString?.string
self.icon.caption.attributedText = attributedString
self.icon.caption.textColor = UIColor.whiteColor()
self.icon.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.icon.caption.textAlignment = .Center
self.iconiPhone47.caption.attributedText = attributedString
self.iconiPhone47.caption.textColor = UIColor.whiteColor()
self.iconiPhone47.caption.font = UIFont(name: "StagSans-Light", size: 16)
self.iconiPhone47.caption.textAlignment = .Center
}
if let storedActivated = eachResult.valueForKey("activated") as? String {
if storedActivated == "0" {
self.icon.imageView.hidden = true
self.icon.caption.hidden = true
self.iconiPhone47.imageView.hidden = true
self.iconiPhone47.caption.hidden = true
}
}
}
}
} // END PRODUCT
//icon.caption.text = stringArray[0]
//icon.category.text =
// Return the cell
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return iconiPhone47
}
else {
return icon
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment