Skip to content

Instantly share code, notes, and snippets.

View NikhilManapure's full-sized avatar
🎯
Focusing

Nikhil Manapure NikhilManapure

🎯
Focusing
View GitHub Profile
+ (NSString*)stringByRemovingEmojiFrom:(NSString*)string {
NSMutableString* __block buffer = [NSMutableString stringWithCapacity:[string length]];
[string enumerateSubstringsInRange:NSMakeRange(0, [string length])
options:NSStringEnumerationByComposedCharacterSequences
usingBlock: ^(NSString* substring, NSRange substringRange, NSRange enclosingRange, BOOL* stop) {
[buffer appendString:([[self class] isEmoji:substring])? @"": substring];
}];
return buffer;
@NikhilManapure
NikhilManapure / BadCellForRowAt.swift
Last active January 10, 2017 05:17
Bad way to write cellForRowAt
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Clean up
if [self.subviews containsObject: self.someNotoriousView] {
[self.contentView removeFromSuperview];
}
// Set up(adding that notorious view again based on some condition )
...
}
@NikhilManapure
NikhilManapure / GoodCellForRowAt.swift
Created January 10, 2017 05:18
Good way to write cellForRowAt
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Set up(adding that notoroious view again based on some condition )
...
}
override func prepareForReuse() {
// Clean up
if [self.subviews containsObject: self.someNotoriousView] {
[self.contentView removeFromSuperview];
}
}
func play(sound: String, ofType type: SoundExtension) {
if let soundID = notificationSoundLookupTable[sound] {
AudioServicesPlaySystemSound(soundID)
} else {
if let soundURL : CFURL = Bundle.main.url(forResource: sound, withExtension: type.rawValue) as CFURL? {
var soundID : SystemSoundID = 0
let osStatus : OSStatus = AudioServicesCreateSystemSoundID(soundURL, &soundID)
if osStatus == kAudioServicesNoError {
AudioServicesPlaySystemSound(soundID);
notificationSoundLookupTable[sound] = (soundID)
enum SoundExtension : String{
case caf
case aif
case wav
}
var notificationSoundLookupTable = [String: SystemSoundID]()
func disposeSoundIDs() {
for soundID in notificationSoundLookupTable.values {
AudioServicesDisposeSystemSoundID(soundID)
}
}
play(sound: "ShortRing", ofType: .wav)
class NMView: UIView {
@IBInspectable var text: String? {
didSet { label.text = text }
}
var label: UILabel!
}