Tuesday, July 29, 2014

Xamarin Basics iOS -Button Click


Steps
1. You have to add button on UI (xib from xcode)
2.Create outlet for button (In xcode itself)
3.Go to corresponding .cs class (In Xamarin Studio)
4.Write the following code

btnName.Activated+=(Object sender,EventArgs e )=>{
               // You can write the code here,that you want to perform in button click
            };



Friday, July 25, 2014

Modern Objective c



Use 'Modern Objective-C Syntax'

Objective-C makes heavy use of the @ operator, which generally denotes Objective-C objects. For example, "string" is a char*, while @"string" is an NSString. These have been standard in Objective-C for a long time, but only recently, in Objective-C 2.0, did Apple add in definitions for NSDictionary, NSArray, and NSNumber, all using literals specified with @ directives.

-----------------------------------------------------------------------------------------------------
NSNumber *number = [NSNumber numberWithInteger:7];
NSNumber *modernNumber = @(7); // or @7
-----------------------------------------------------------------------------------------------------
NSArray *array = [NSArray arrayWithObjects:number, modernNumber, nil];
NSArray *modernArray = @[number, modernNumber];
-----------------------------------------------------------------------------------------------------
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:number, @"number"];
NSDictionary *modernDictionary = @{@"number" : number};
-----------------------------------------------------------------------------------------------------


It's more concise, and still somehow more readable.


Enum 

Replace your enum declarations, such as this one:
enum {

        UITableViewCellStyleDefault,

        UITableViewCellStyleValue1,

        UITableViewCellStyleValue2,

        UITableViewCellStyleSubtitle

};

typedef NSInteger UITableViewCellStyle;


with the NS_ENUM syntax:



typedef NS_ENUM(NSInteger, UITableViewCellStyle) {

        UITableViewCellStyleDefault,

        UITableViewCellStyleValue1,

        UITableViewCellStyleValue2,

        UITableViewCellStyleSubtitle

};


But when you use enum to define a bitmask, such as here:

enum {

        UIViewAutoresizingNone                 = 0,

        UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,

        UIViewAutoresizingFlexibleWidth        = 1 << 1,

        UIViewAutoresizingFlexibleRightMargin  = 1 << 2,

        UIViewAutoresizingFlexibleTopMargin    = 1 << 3,

        UIViewAutoresizingFlexibleHeight       = 1 << 4,

        UIViewAutoresizingFlexibleBottomMargin = 1 << 5

};
typedef NSUInteger UIViewAutoresizing;

use the NS_OPTIONS macro.


typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {

        UIViewAutoresizingNone                 = 0,

        UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,

        UIViewAutoresizingFlexibleWidth        = 1 << 1,

        UIViewAutoresizingFlexibleRightMargin  = 1 << 2,

        UIViewAutoresizingFlexibleTopMargin    = 1 << 3,

        UIViewAutoresizingFlexibleHeight       = 1 << 4,

        UIViewAutoresizingFlexibleBottomMargin = 1 << 5

};

Alternatively, you can use the modern Objective-C converter in Xcode to make this change to your code automatically. 

Thursday, June 19, 2014

iOS -Swift Basics

The Basics
Swift does away with the standard of declaring variables by starting with their type names, and instead opts to use a Javascript-like ‘var’ keyword to define any variable.
So for instance in Objective-C where you have this:
NSString *myString = @"This is my string.";
You now have this:
var myString = "This is my string."
Meanwhile constants are expressed with the ‘let’ keyword
let kSomeConstant = 40
In this case kSomeConstant is implicitly defined as an integer. If you want to be more specific you can specify which type it is like so:
let kSomeConstant: Int = 40
With both arrays and dictionaries, they are described using brackets []
var colorsArray = ["Blue", "Red", "Green", "Yellow"]
var colorsDictionary = ["PrimaryColor":"Green", "SecondaryColor":"Red"]

Monday, June 2, 2014

Apple talks iOS 8

Quick Reply: iOS 8 features the ability to quickly respond to messages from Notification Center as well as the lock screen

Favorite Contacts in Multitasking: Favorite contacts are now available in the multitasking view

Safari for iPad has new tabs view: The same tabs view from Safari on iPhone is now available on iPad as well as OS X Yosemite’s sidebar

Quick reply for third party apps: This includes apps like Facebook

Mail gestures and management improvements: Similar to Mailbox, gesture based actions and deeper integration with Calendar and better multitasking within Mail

SpotlightSpotlight now has more advanced features on iOS similar to OS X Yosemite including in-line results from Wikipedia and music on iTunes. Spotlight is also built-in to Safari’s search field as an alternative to Google Search

Quicktype: iOS 8 features a keyboard feature called Quicktype which is an alternative keyboard with suggestive typing with context awareness. Typing learning is private to the device so not shared or accessible by others; securely implemented.

Continuity: Same continuity features demoed under Yosemite.

Messages: Support for naming threads and group message management. This includes Do Not Disturb support per thread and the ability to leave the thread. Sharing is also made easier with the iOS 8 version of Messages including attachment management and voice, photo, and video sharing. Location sharing is also made much easier.
Messaging is very similar to Facebook’s Messenger app in terms of sharing photos and videos quickly as well as voice. Audio and video messages are allowed to delete after a period of time to avoid large files clogging up storage similar to Snapchat and other message apps. Audio messages can be heard from the lock screen using a Raise to Hear feature.

iCloud Drive: iCloud Drive allows users to work with documents across applications on iOS 8 using documents stored in iCloud.

Enterprise: iOS 8 includes a new enrollment program making enterprise device usage much easier.
HealthKit & Health: HealthKit is a feature that speaks with fitness and health apps to pull information from various apps into a single app called Health that centralizes results. The software features integration with the Mayo Clinic. It can present weight, activity, heart rate, and more.

Family Sharing: This feature brings together family photo streams, calendars, reminders, Find My Friends, and even shared purchases up to six family members on iTunes, App Store, and iBooks. This is connected by the credit card.

Photos: iCloud now stores all photos including more than what can fit on the device. Photos also includes advanced search features now with perimeters like time, location, and albums.
Photos also now features advanced editing features within the app. Photos and videos are backed up to iCloud at full resolution, but requires iCloud storage space. New pricing and storage tiers will be available.

Shazam: Siri will support Shazam for music recognition in iOS 8 as well as feature a hands-free mode with the Hey Siri command.

Availability: iOS 8 will be available in beta today for developers and publicly this fall.

Apple Launches Swift, A New Programming Language For Writing iOS And OS X Apps

At its WWDC developer event today, Apple surprised all of the developers in the audience by launching a new programming language called Swift. This new language seems to be poised to replace Objective-C as the main programming language on Apple’s platforms.
Swift will use the same LLVM compiler and runtime as Apple’s Objective-C implementation, so Swift and Objective-C code can live side-by-side in the same application. The language provides access to all of the Cocoa and Cocoa Touch features developers are currently used to from Objective-C.
It should feel familiar to those who are already used to Objective-C, Apple says, and is meant to “unify the procedural and object-oriented portions of the language.” It does diverge from Objective-C in more than just the syntax, though; it also features variable types like tuples and optional types. It also includes operators that aren’t found in Objective-C, which allow you to perform remainder operations on floating-point numbers, for example.
Here are some of the highlights of the language according to Apple:
  • Closures (similar to blocks in C and Objective-C) unified with function pointers
  • Tuples and multiple return values
  • Generics
  • Fast and concise iteration over a range or collection
  • Structs that support methods, extensions, protocols.
  • Functional programming patterns, e.g.: map and filter
In addition, Apple notes how the language was designed for safety, with variables that have to be initialized before use, arrays and integers that are checked for overflow and automatic memory management.
Swift support, of course, will be deeply integrated into Apple’s updated Xcode IDE. It will feature an interactive “Playground” that allows you to edit your code and watch how your changes influence your app in real-time. Xcode’s debugging console now also supports Swift syntax natively.
IMG_0258
According to Apple, Swift will provide a number of significant speed advantages to developers. A complex object sort, for example, will run 3.9x faster than an implementation of the same algorithm in Python. That’s also faster than Objective-C, which is 2.8x faster than the Python version.
IMG_0254
We will obviously need to take a closer look at this new programming language and how it relates to other languages. Apple is making the documentation available today, both as an iBook and on its developer site.
Objective-C was always a hard language to pick up for new developers. We will also have to see if Swift makes getting started with app development on Apple’s platforms easier, but from a first look at the documentation, it definitely feels more accessible than Objective-C.
IMG_0266

Sunday, May 25, 2014

NSUserDefaults Security Issue - iOS



Some developers don’t prefer to save data in the Keychain because it is not that straightforward to implement . However, saving info in the Keychain is probably the most secure way of storing data on a non-jailbroken device. Basically, the code for saving data in the keychain is just like saving data with NSUserDefaults with this wrapper. Here is a snippet of code that saves a string to the keychain. Notice that the syntax looks very similar to using NSUserDefaults.


1
2
PDKeychainBindings *bindings = [PDKeychainBindings sharedKeychainBindings];
[bindings setObject:@"XYZ" forKey:@"authToken"];
And here is a small snippet for fetching data from the keychain.
1
2
PDKeychainBindings *bindings = [PDKeychainBindings sharedKeychainBindings];
NSLog(@"Auth token is %@",[bindings objectForKey:@"authToken"]]);


Tuesday, May 20, 2014

Predicate Format String Syntax

The parser string is different from a string expression passed to the regex engine. This article describes the parser text, not the syntax for the regex engine.

Parser Basics

The predicate string parser is whitespace insensitive, case insensitive with respect to keywords, and supports nested parenthetical expressions. The parser does not perform semantic type checking.
Variables are denoted with a $ (for example $VARIABLE_NAME). ? is not a valid parser token.
The format string supports printf-style format arguments such as %x (see “Formatting String Objects”). Two important arguments are %@ and %K.
  • %@ is a var arg substitution for an object value—often a string, number, or date.
  • %K is a var arg substitution for a key path.
When string variables are substituted into a format string using %@ , they are surrounded by quotation marks. If you want to specify a dynamic property name, use %K in the format string, as shown in the following example.
NSString *attributeName = @"firstName";
NSString *attributeValue = @"Adam";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",
        attributeName, attributeValue];
The predicate format string in this case evaluates to firstName like "Adam".
Single or double quoting variables (or substitution variable strings) cause %@%K, or $variable to be interpreted as a literal in the format string and so prevent any substitution. In the following example, the predicate format string evaluates to firstName like "%@" (note the single quotes around %@).
NSString *attributeName = @"firstName";
NSString *attributeValue = @"Adam";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like '%@'",
        attributeName, attributeValue];

Basic Comparisons

===
The left-hand expression is equal to the right-hand expression.
>==>
The left-hand expression is greater than or equal to the right-hand expression.
<==<
The left-hand expression is less than or equal to the right-hand expression.
>
The left-hand expression is greater than the right-hand expression.
<
The left-hand expression is less than the right-hand expression.
!=<>
The left-hand expression is not equal to the right-hand expression.
BETWEEN
The left-hand expression is between, or equal to either of, the values specified in the right-hand side.
The right-hand side is a two value array (an array is required to specify order) giving upper and lower bounds. For example, 1 BETWEEN { 0 , 33 }, or $INPUT BETWEEN { $LOWER, $UPPER }.
In Objective-C, you could create a BETWEEN predicate as shown in the following example:
NSPredicate *betweenPredicate =
    [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", @[@1, @10]];
This creates a predicate that matches ( ( 1 <= attributeValue ) && ( attributeValue <= 10 ) ), as illustrated in the following example:
NSPredicate *betweenPredicate =
    [NSPredicate predicateWithFormat: @"attributeName BETWEEN %@", @[@1, @10]];
 
NSDictionary *dictionary = @{ @"attributeName" : @5 };
 
BOOL between = [betweenPredicate evaluateWithObject:dictionary];
if (between) {
    NSLog(@"between");
}

Boolean Value Predicates

TRUEPREDICATE
A predicate that always evaluates to TRUE.
FALSEPREDICATE
A predicate that always evaluates to FALSE.

Basic Compound Predicates

AND&&
Logical AND.
OR||
Logical OR.
NOT!
Logical NOT.

String Comparisons

String comparisons are by default case and diacritic sensitive. You can modify an operator using the key characters cand d within square braces to specify case and diacritic insensitivity respectively, for example firstName BEGINSWITH[cd] $FIRST_NAME.
BEGINSWITH
The left-hand expression begins with the right-hand expression.
CONTAINS
The left-hand expression contains the right-hand expression.
ENDSWITH
The left-hand expression ends with the right-hand expression.
LIKE
The left hand expression equals the right-hand expression: ? and * are allowed as wildcard characters, where ?matches 1 character and * matches 0 or more characters.
MATCHES
The left hand expression equals the right hand expression using a regex-style comparison according to ICU v3 (for more details see the ICU User Guide for Regular Expressions).

Aggregate Operations

ANYSOME
Specifies any of the elements in the following expression. For example ANY children.age < 18.
ALL
Specifies all of the elements in the following expression. For example ALL children.age < 18.
NONE
Specifies none of the elements in the following expression. For example, NONE children.age < 18. This is logically equivalent to NOT (ANY ...).
IN
Equivalent to an SQL IN operation, the left-hand side must appear in the collection specified by the right-hand side.
For example, name IN { 'Ben', 'Melissa', 'Nick' }. The collection may be an array, a set, or a dictionary—in the case of a dictionary, its values are used.
In Objective-C, you could create a IN predicate as shown in the following example:
NSPredicate *inPredicate =
            [NSPredicate predicateWithFormat: @"attribute IN %@", aCollection];
where aCollection may be an instance of NSArrayNSSetNSDictionary, or of any of the corresponding mutable classes.
array[index]
Specifies the element at the specified index in the array array.
array[FIRST]
Specifies the first element in the array array.
array[LAST]
Specifies the last element in the array array.
array[SIZE]
Specifies the size of the array array.

Identifiers

C style identifier
Any C style identifier that is not a reserved word.
#symbol
Used to escape a reserved word into a user identifier.
[\]{octaldigit}{3}
Used to escape an octal number ( \ followed by 3 octal digits).
[\][xX]{hexdigit}{2}
Used to escape a hex number ( \x or \X followed by 2 hex digits).
[\][uU]{hexdigit}{4}
Used to escape a Unicode number ( \u or \U followed by 4 hex digits).


Literals

Single and double quotes produce the same result, but they do not terminate each other. For example, "abc" and'abc' are identical, whereas "a'b'c" is equivalent to a space-separated concatenation of a'b'c.
FALSENO
Logical false.
TRUEYES
Logical true.
NULLNIL
A null value.
SELF
Represents the object being evaluated.
"text"
A character string.
'text'
A character string.
Comma-separated literal array
For example, { 'comma', 'separated', 'literal', 'array' }.
Standard integer and fixed-point notations
For example, 1272.7182819.75.
Floating-point notation with exponentiation
For example, 9.2e-5.
0x
Prefix used to denote a hexadecimal digit sequence.
0o
Prefix used to denote an octal digit sequence.
0b
Prefix used to denote a binary digit sequence.