Common method in Swift


1. Check for any field empty in NSDictionary class func checkforEmptyValueinDictioanty(dic:NSDictionary)-> Bool{ for (keyVal, dataVal) in dic {   if (dataVal.length()==0){                 println("\(keyVal): \(dataVal.length())")                 return false             }                 ... Continue Reading →

Advertisements

Use different font text in a Label in swift


let secondLabel=UILabel(frame: CGRectMake(0, 16, _screenWidth-2, 20))         secondLabel.textColor=UIColor.whiteColor()         secondLabel.textAlignment=NSTextAlignment.Center         secondLabel.font=UIFont(name: "Arial", size: 12)         bottomView.addSubview(secondLabel)                  let attrSting=NSMutableAttributedString(string: "I agree to the Terms of Service and Privacy Policy.")             ... Continue Reading →

Check if NSString contains alphanumeric + underscore characters only


Step 1. First create your own character set. NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString: @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_"];  Step 2. Once you have that, you invert it to everything that's not in your original string: set = [set invertedSet]; Step : 3 NSRange r = [string rangeOfCharacterFromSet:s]; if (r.location != NSNotFound) { NSLog(@"the string contains illegal characters"); }

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: