Tuesday, October 11, 2016

Swift 3:- Array Tutorials

These are formatted so you can copy the code straight into your Swift Playground files.


//create an empty array containing String types
var swift3Array = [String]()
swift3Array.append("Tutorials")
swift3Array.append("More Tutorials")
//remove an item
swift3Array.remove(at: 0)  //remove first item
//remove everything
swift3Array.removeAll()
//add stuff back...
swift3Array = ["CartoonSmart.com" , "Shameless Plug", "Best Tutorials for Swift 3"]
// check if the array has a specific thing...
for name in swift3Array {
    //for loop iterates through all Strings in the array
    if (name == "CartoonSmart.com") {
        // found the one we are looking for
        print("found")
        break
    }
    
}
// check if a specific index equals something
if ("Best Tutorials for Swift 3" == swift3Array[2] ) {
    
    // remember the 2 in swift3Array[2]  means that actually the third item in th array since indexing starts at 0
     print("true dat")
}


Swift 3 Tutorials :- String and Character Variables

 These are formatted so you can copy the code straight into your Swift Playground files.

/// variable of Character type that is just a single character
var singleLetter:Character = "F"
// string type variable, contains as many letters, numbers, etc as you want
var mishMash:String = "sdf2325&803!!~"
// create an array of Characters
var letters:[Character] = ["C", "A","R", "T","O", "O","N", "S","M", "A","R", "T", ".", "c", "o", "m"]
//convert the letters array into a string variable named website
var website:String = String (letters)
// lets play around....
print (letters.count)  // prints the number of objects in the array
print (website.characters.count ) //prints the same value
//test to see if converting it all to lower case equals "cartoonsmart.com"
if ( website.lowercased() == "cartoonsmart.com") {
    print (website.lowercased())
    //note in Swift 3 this is lowercased(). In Swift 2 it was lowercaseString
}
let capFirstLetters = website.capitalized  //capFirstLetters would be "Cartoonsmart.Com"
//note in Swift 3 this is .capitalized. In Swift 2 it was capitalizedString
//test to see if website contains a range of ".com"
if ( website.range(of: ".com") != nil) {
    //note in Swift 2, this would have been .rangeOfString(".com")
    print ("it has the dot com")
}
if ( website.lowercased().hasPrefix("car")) {
    //do something if the string begins with "car"
    print ("true")
}
if ( website.hasSuffix(".net")) {
    // do something if its .net
    print ("true")
} else {
    //its not .net
    print ("not true")
}




Thursday, October 6, 2016

iOS 10 logging out with XCode 8 NSUserDefaults getting empty






Hi Guys,

There is issue on upgrade of iOS 9 to iOS 10, NSUserDefaults(in Objective-C) or UserDefaults(in Swift) getting empty, Because of that App forcefully back to first screen of the app. (happing with whatsapp , facebook ), Its iOS issues.

But the time Apple solve the bug on next version of iOS, mean the while there is hot fix solution for this issues.

This issue is happing because of NSUserDefaults getting empty, So we need sure that, It shouldn't be empty, here I am store the NSUserDefaults dictionary into serialize file while going into background mode the app.

//Getting dictionary from NSUserDefaults
NSDictionary *defaultsDictionary  = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];

// Storing the dictionary into serialize file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent: @"myFile.ser"];
[NSKeyedArchiver archiveRootObject: defaultsDictionary toFile:filePath];
// Retrieving the Dictionary from serialize file
 NSDictionary *restoreDictionary = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];

Once you Get the Stored dictionary from the serialize file, afterthat check whether NSUserDefaults getting empty or not, if its empty than put this code

NSDictionary *restoreDictionary = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
// here we are filling the NSUserDefaults once again....
for (id key in restoreDictionary) {
[[NSUserDefaults standardUserDefaults]
removeObjectForKey:key];
[[NSUserDefaults standardUserDefaults]; objectForKey:keyName];
}
 [[NSUserDefaults standardUserDefaults]
 synchronize];

this way I have solved my issues... for hot fix... Once Apple will resolve this issue.. I'll remove that fix...

Hope you guys that will you.... If something is missing please let me know...!!!!


Thanks,
Indra Patel
Mumbai

Sunday, February 14, 2016

svn tagging in Xcode using iSVN


Download iSVN from  http://www.einhugur.com/iSvn/



Add root directory of xcode project.



Open Browse Repository 



* Select the trunk folder of project in the repository and copy the trunk file paste into tag folder with tag name.




Thanks,




Wednesday, December 4, 2013

Calendar - Multi-dates selection

Calendar library for iOS platform.

I have seen many library from https://www.cocoacontrols.com/platforms/ios/controls but haven't got any solution which i really want than i have downloaded one of the library than customize the calendar library. Now user can select multiple dates or single date from this library and it will return NSMutable Array of selected dates.






This way we can select multiple dates from calendar view. by pressing back button it will return all selected dates in Array.

for download this library follow this link:-
https://github.com/IndraPatel123/CalendarLibrary