Relatively new to Swift programming.
I get an dictionary from which I need to get the user name (first and last name) and display it in table view cell along with other data.
On iPhone 5 and below as the screen width is only 320, the requirement is to just display the first name and first character of the last name.
E.g: "Howard Mark" to "Howard M"
I am sure that there is an elegant way to extract the required string.
struct ScreenSize
{
static let SCREEN_WIDTH = UIScreen.main.bounds.size.width
static let SCREEN_HEIGHT = UIScreen.main.bounds.size.height
static let SCREEN_MAX_LENGTH = max(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
static let SCREEN_MIN_LENGTH = min(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
}
struct DeviceType
{
static let IS_IPHONE_5_OR_LESS = (UIDevice.current.userInterfaceIdiom == .phone && ScreenSize.SCREEN_MAX_LENGTH <= 568.0)
}
func functionCall (referralData:[String: Any?])
{
var myMutableString = NSMutableAttributedString()
if var nameString = referralData[KEY_FULL_NAME]
{
if DeviceType.IS_IPHONE_5_OR_LESS
{
var a = nameString as? NSString
var arr = a?.components(separatedBy: " ")
let newStr = arr?[0] as? String
nameString = newStr
if((arr?.count)! > 1)
{
if let secondString = arr?[1]
{
let newStr2 = newStr as? NSString
let secondChar = newStr2?.character(at: 0)
let stringchar:String! = String(secondChar!)
nameString = "\(newStr!) \(stringchar)"
}
}
print("iPhone 5 or less")
}
else
{
print("Greater than iPhone 5")
}
}
}