Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Objective C

Featured

Set the maximum date in UIDatePicker to Today

To set the maximum date of date picker in ios to today. for example , if we want to pick the date of birth of a user then the date is can not be greater then today date . So we can use following step to set the maximum date of datePicker ...

How to play a video file ios

Hello Friends, Create an object of MPMoviePlayerController: MPMoviePlayerViewController *moviePlayerController; NSURL *videoUrl=[NSURL URLWithString:@"String value of your url"]; Initialize the instance of MPmoviePlayerViewControl...

Crop Image in iOS

To crop image in iOS use the following method. it will crop the image from the visible frame of the imageView. -(UIImage *)imageFromImageView:(UIImageView *)imageView rectFrame:(CGRect)frame{ UIGraphicsBeginImageContextWithOptions(frame....

login to facebook in ios 9.0

to login using facebook in iPhone sdk please use the code below. install the pods for facebook using pod "FBSDKCoreKit"; pod "FBSDKLoginKit"; pod "FBSDKShareKit"; pod "FBSDKMessengerShareKit" import FBSDKLoginKit ...

C Preprocessor directives

The preprocessing of C source code is done before it is compiled by the compiler. The Preprocessor directives are the command used for preprocessing which starts with "#" symbol. The list of preprocessor directives that C language offers is given...

How to display annotation on any Location in MKMapView

If we want to display the annotation point on any coordinates in MKMapView use the following functions- By using the annotation anyone can easily recognize the location.We can also set the Title here which will show when user click on that...

How to use Flow Layout in UICollectionview

cells in UICollectionview can be of same Size or different sizes, so we use the flow layout. UICollectionViewFlowLayout manage items into a grid with header and footer view for every section. Here we define the flow layout-- -(void)viewDidL...

How to set placeholder text in uitextview

If we want to set the placehoder text in uitextview then we have to use the delegates methods of textview because there is not an option to set the placeholder directly in xcode. Here is the methods-- - (void)viewDidLoad { [super vi...

Set Dynamic Size of button according to the Title text

if you want to change the size of UIButton according to the title text then use the following function-- -(void)setDynamicSizeOfButton:(UIButton *)button andSize:(CGFloat)Size { CGSize size = [button.titleLabel.text sizeWithAttributes: ...

How to Show a pdf File from URL in a UIWebview in iOS

when we want to open the pdf file from a URL string then we use the UIWebView. In webview we can directly open the file by loading the url request.use the following function-- -(void)addWebViewOverLay:(UIWebView *)webView { webView = [[UI...

Seat Selector For iOS

Hi All, Now days , we start booking seats online so if you also want to implement seat selection functionality than follow these steps . Download ZSeatSelector from this link https://github.com/richzertuche/ZSeatSelector Now drag two fil...

Show a route between two coordinates using MKMap view in iOS

In ios when we want to show a route or poly line between two coordinate then we use the following function. most of time we use this when we want to dislplay the route from current location to destination address. Here mapView is the property...

Show The Contact List in iOS

To show the list of contact in iPhone use the code Below: 1- import the ContactsUI framwork in viewController 2- Confrom the ViewController to the CNContactPickerDelegate 3- call the delegate method func contactPicker(picker: CNContactPicke...

Convert NSString to NSDate and vice versa

HI all, If you want to convert NSString to NSDate ,then you must use NSDateFormatter to convert please follow this code . NSString to NSDate In Objective-C :- NSString *dateString = @"11-11-2015"; NSDateFormatter *dateFormatter = [[...

add touch event to UIView

To provide some action on touch of any view ,UITapGestureRecognizer is used. Write this code in viewDidLoad - (void)viewDidLoad { [super viewDidLoad]; myView.userInteractionEnabled = YES; UITapGestureRecognizer *singleFingerTap = ...

How to check user current notification setting in objective C

hello friends , You can check user's current notification setting by following line of codes. // this method is deprecated in iOS 8.0 UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; i...

Blur Effect on screen in iOS

To add the blur Effect on screen please follow the below steps Select an image on which you want to add the blur effect. Add an imageView on screen with the size you want blur effect on screen. Add the effect with the same size on which yo...

Caputre Screen Shot in IPhone

if you want to capture the screen shot of the screen in swift use the code below. this function will return an image that can be used as background image of a view The size of the captured image is same as the size of device. func caputreSc...

date picker in place of keyboard in UITextField

The date picker is used to pick date for textfield. It is placed in textFieldDidBeginEditing (a delegate method of UITextField), so that the keyboard is replaced with date picker as soon as you enter into textfield. updateTextField will set the ...

test if an NSString is empty in Objective C

You can check if( [empName length]==0 || [[empName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) this will return 1 else 0 NSString *empName; if ([empName length]==0 || [[empName stringByTrimmingCharac...

Check for the iPhone Models

To know On which hardware iOS is ruining like iPhone4 , iPhone5 etc below is the code for that #import <sys/utsname.h> -(NSString*) deviceName { struct utsname systemInfo; uname(&systemInfo); r...

Error in __weak typeof(self)weakSelf = self

If you have error in line __weak typeof(self)weakSelf = self; replace this line with __typeof__(self) __weak weakSelf = self;

Play a video from a URL in iPhone SDK

To play a video from a url in iPhone sdk just write down following line of code: Step 1: Create a MPMoviePlayerViewController object as *moviePlayerController. Step 2: Create a Url and initialize your movieController with Url. Step 3: and No...

Download Files Using DropBoxSDK in iOS

If You want to get the list of all the files that are uploaded on your DropBox then use the following code : method -(void)downloadAllData:(void (^)(NSMutableArray *, NSMutableArray *, BOOL)) block need to be called after the successful lo...

Invalid attempt to access ALAssetPrivate past the lifetime of its owning ALAssetsLibrary

When accessing assets in the iPhone, some time users gets this error. (Invalid attempt to access ALAssetPrivate past the lifetime of its owning ALAssetsLibrary) so we can initialize our assetLibaray using the following code: + (ALAssets...

How to convert NSData to NSString or vice versa in Objective C and Swift

Hi Readers! In this blog you can find both versions (Obj C & Swift) for converting NSData to NSString or vice-versa. Objective C NSString * str = @"Hello"; NSData * data =[str dataUsingEncoding:NSUTF8StringEncoding]; NSLog(@"Data = ...

DropBox Login Integration Using iOS SDK

Download the DropBox SDK from the https://www.dropbox.com/developers/sync/sdks/ios add this sdk to Your project and also add some other Frameworks. 1. Foundation.framework 2. UIKit.framework 3. CoreGraphics.framework 4. QuartzCore.fra...

Fetch profile pic from Facebook

For some reasons Facebook doesnt provide profile picture with user info dictionary/data. We need to fetch profile pic using graph api. Once user is done with successful authentication he can use following snippet to get profile picture URL. ...

How to iterate or remove all key object from NSUserDefaults

Hi Readers, In any iPhone app if it is needed to iterate or remove NSUserDefault keys (as in logout feature), following code can be used: To iterate key objects: NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; ...

How to get sub strings from a string using Regular Expression

Hi, The below code is to get substrings from a string. You are going to love this below code which is very simple but very effective. I have used regular expression to get the sub strings. NSString *strTest = @"Hii how are you doing @Ravi , h...

Protocols it's usage and Types

Protocols are powerful functionality provided by iOS. These are set of behavior that is expected from an object to behave/respond in a given situation. Protocols are set of methods and properties. One can define protocol as: @protocol protoco...

When to use copy Attribute in declaring a property in objective c

We all use attributes in Objective C to declare properties. Attributes commonly used are strong, nonatomic, weak, assign. But we never take it seriously why we are using these attributes. One of the common mistakes I often see is the wrong us...

__weak and __unsafe_retained

__weak and __unsafe_unretained are the ownership qualifiers introduced by LLVM Compiler 3.0. By default all pointers are __strong under ARC which means that when an object is assigned to a pointer, it is retained for as long as that pointer re...

Tabbar Customization

Snippet works all around to customize the tabbar icons & texts display color for selected and unselected state for iOS7 self.tabbarController.tabBar.tintColor = [UIColor greenColor]; Below code can be used to customize the text look. ...

Objective C coding style

Language US English should be used. Preferred: UIColor *myColor = [UIColor whiteColor]; Not Preferred: UIColor *myColour = [UIColor whiteColor]; Code Organization Use #pragma mark - to categorize methods in functional groupin...

How to copy image in NSPasteBoard

To copy the image on NSPasteBoard following code can be used: - (IBAction)paste:sender { NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; NSArray *classArray = [NSArray arrayWithObject:[NSImage class]]; ...

How to print an NSImage

The following code prints an image stored in a file: -(void)print:(id)sender { NSImage *image = [[NSImage alloc]initWithContentsOfFile:[imageEdWindowController getImageLocation]]; [image scalesWhenResized]; NSImageView *&#9...

How to send email in mac os

Following code can be use to send email in mac os: -(IBAction)sendEmailClicked:(id)sender { NSString *recipient; NSString *mailsender; NSString *mailsubject; NSString *mailmessage; recipient = [reciever stringValue]; ...

How to convert NSImage to NSImageRep

You can convert NSImage to NSImageRep by using the following method: - (NSImageRep*)bitmapImageRepresentation:(NSImage*)image { NSArray *ret =[image representations]; for(NSImageRep *rep in ret) if([rep isKindOfClass:[NSIma...

How to convert NSImage to CIImage

To convert NSImage to CIImage following function can be used. -(CIImage*)fromNSImage:(NSImage*)image { NSData * tiffData = [image TIFFRepresentation]; NSBitmapImageRep * bitmap; bitmap = [NSBitmapImageRep imageRepWithData:tiff...

How to convert CIImage to NSImage

You can convert CIImage to NSImage by using the following function: -(NSImage*)fromCIImage:(CIImage*)ciImage { NSCIImageRep *imageRep = [NSCIImageRep imageRepWithCIImage:ciImage]; NSImage *_image = [[NSImage alloc] initWithSize:[ima...

How to redirect console logs to a file

To redirect the log statements to a file instead of console call the following function at the start of function applicationDidFinishLaunching. - (void)redirectConsoleLogToDocumentFolder { NSArray *paths = NSSearchPathForDirectoriesInDom...

Use of NSSharingServicePicker

The NSSharingServicePicker class presents a list of sharing services, so that the user can choose a service to share an item. When a service is chosen, the picker automatically executes it, which presents the sharing window. + (NSMenu *)menuFo...

NSSplitView delegate for controlling minimum and maximum sizes of views

NSSplitView have delegate methods where we control the minimum and maximum sizes of sections and which views expand or collapse by what amount. Constraining the coordinates in the splitView:constrainMinCoordinate:ofSubviewAt: sets the minimum ...

NSSplitView delegate for priority based resizing

The default resizing mechanism in NSSplitView is proportional resizing in which if the NSSplitView changes size, each column resizes by an equal percent. But it is not successful in case where the columns in a split view are used to separate a si...

Cut image through code in mac os

Method to cut image in Objective-c/cocoa (OSX) -(IBAction)cutItem:(id)sender { hasBeenDragged = NO; NSImage *_sourceImage = [self image]; float width = selectedArea.size.width; float height = selectedArea.size.height; ...

Crop image in mac os

If you want to crop the image without changing its quality in Objective-c/cocoa (OSX) then you can use the following method -(IBAction)crop:(id)sender{ hasBeenDragged = NO; NSImage *_sourceImage = [self image]; float width = sel...

Memory management under ARC

ARC Memory management 1)Methods you cant call (or override) anymore You will have to remove all calls to these methods without substitution: 1)retain 2)retainCount 3)release 4)autorelease 5)Dealloc You also cant use the re...
prev 1 2 next
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: