Skip to main content

Program Objective-C

1 - A Program in Objective C Method Function Declaration, Definition With Calling.

#import <Foundation/Foundation.h>

@interface SampleClass: NSObject

-(int)max:(int)num1 secondNumber:(int)num2;

@end

@implementation SampleClass

-(int)max:(int)num1 secondNumber:(int)num2
{
int result;
if(num1 > num2)
{
result = num1;
}
else{
result = num2;
}
return result;
}
@end

//Variable declaration
int a;
int b;
int main()
{
//Variable defination
int a = 10;
int b = 20;
int c;
int ret;
c = a + b;
NSLog(@"Value of c : %d \n", c);
f = f/10.10;
NSLog(@"Value of c : %f \n", f);
SampleClass *sampleClass = [[SampleClass alloc]init];
ret =  [sampleClass max:a secondNumber:b];
NSLog( @"Max value is :%d\n", ret );

return 0;

}

Object Oriented Programming Feature in Swift


Classes and Objects

Create A Class 

Class A{
//Empty Class
}
Create a new instance new Object in a Class A
Class A{
var new = A()
}

Properties 

Class B{

var data: Int = 10

}

1 TO 5 - Number Pattern Program in Objective C

(1):- 

12345
1234
123
12
1

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])

{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

int i, j;    
    for(i=5; i>=1; i--)  
{
   for(j=1; j<=i; j++)      
 {          
         NSLog(@"%i", j);    
    }      
         NSLog(@"");
   
}
[pool drain];
return 0;
}

(2):- 

5
54
543
5432
54321


#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int i, j;  
for(i=5; i>=1; i--)
        {  
for(j=5; j>=i; j--)    
{        
NSLog(@"%i", j);    
}      
NSLog(@"");  
}
[pool drain];
return 0;
}

(3):- 

54321
4321
321
21
1

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int i, j;  
for(i=5; i>=1; i--)
 {      
for(j=i; j>=1; j--)
          
NSLog(@"%i", j);      
}
       
NSLog(@"");
   
}

[pool drain];
return 0;
}

(4):- 

54321
5432
543
54
5

#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int i, j;
   
for(i=5; i>=1; i--)
   
 {
       
for(j=i; j>=1; j--)          
NSLog(@"%i", j);
     
}
       
NSLog(@"");
   
}
[pool drain];

return 0;
}

(5):- 

5
45
345
2345
12345

#import <Foundation/Foundation.h>


int main (int argc, const char * argv[])

{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

int i, j;
   
for(i=5;i>=1;i--)
   
  {
       
for(j=i;j<=5;j++)
       
{          
NSLog(@"%d", j);
       
  }
       
NSLog(@"");
   
 }
 

[pool drain];

return 0;

}



(6):-

1
21
321
4321
54321

#import <Foundation/Foundation.h>


int main (int argc, const char * argv[])

{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];


for(i=1;i<=5;i++)

 {

for(j=i;j>=1;j--)

 {                  
NSLog(@"%d", j);
       
  }
       
NSLog(@"");
   
 }
 

[pool drain];

return 0;

}


(7):-

5
54
543
5432
54321

#import <Foundation/Foundation.h>


int main (int argc, const char * argv[])

{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];


for(i=5;i>=1;i--)
{

for(j=5;j>=i;j--)

{                
NSLog(@"%d", j);
       
  }
       
NSLog(@"");
   
 }
 

[pool drain];

return 0;

}


(8):-

1
22
333
4444
55555

#import <Foundation/Foundation.h>


int main (int argc, const char * argv[])

{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];


for(i=1;i<=5;i++)

{

for(j=1;j<=i;j++)

{                
NSLog(@"%d", j);
       
  }
       
NSLog(@"");
   
 }
 
[pool drain];

return 0;



Comments

  1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

How Create Animated Circle Progress Bar iOS 11 Swift 4

  Animated Circle Progress Bar iOS 11 Swift 4 With MBCircularProgressBa r - https://github.com/MatiBot/MBCircularProgressBar A circular, animatable & highly customizable progress bar from the Interface Builder Swift, Using pod fite MBCircularProgressBar Installation Cocoapods terminal. pod "MBCircularProgressBar" That - A Simple Steps to installed pod file -        Open terminal        Command on terminal go to project folder Cd path        set your project path on terminal.        command : pod init        open pod file - open -e podfile        added in pod file with in : pod "MBCircularProgressBar"        Command : Pod install        Close project of Xcode        open your Project from terminals        Command : open PodDemos.xcworkspace After opern StoryBoard and Now drag a UIView over the viewController in storyboard Or set UIView Constraint width, height or verticle or horzentail space and set a class MBCircul

Add a Scene Delegate to your existing project with Storyboard in Swift

To add a scene delegate, first, create a new Swift file that you’ll call "SceneDelegate" containing a subclass of UIResponder, just like the AppDelegate, and that conforms to UIWindowSceneDelegate.  As your app might supports other versions than iOS 13, make this class only available for iOS 13. This is what you should have : If you are working a project that is storyboard based, please set storyboard  initial view controller SceneDelegate.swift import UIKit @available ( iOS 13.0 , *) class SceneDelegate : UIResponder , UIWindowSceneDelegate {     var window : UIWindow ?     func scene ( _ scene: UIScene , willConnectTo session: UISceneSession , options connectionOptions: UIScene . ConnectionOptions ) {                  let storyboard = UIStoryboard (name: "Main" , bundle: nil )         let initialViewController = storyboard. instantiateViewController (withIdentifier: "ViewController" )         let mainNavigationController = UINavigationControlle

How to Use Multiple Sections in UITableView iOS Swift !

Multiple sections in UITableView iOS Swift. UITableView is very important part of iOS ecosystem. So we split tableviews in sections. Then its easier to find right information.  1. First let’s create a project as usual. Create a new single view application X code project. Set project name to UIViewController.  2. Go to main storyboard & select view controller & use UITableView 3. Select tableview & make it initial view controller  4 Create a custom Sections Class like Name => TableSections, create register cell static return “ getCellNibs ” method. Then create  4 section enum “TableItems” then after append all sections to an array model. import UIKit struct CellNib {      static func getCellNibs () -> [ String ] {          return [ "Cell1" , "Cell2" , "Cell3" , "Cell4" ]     } } enum TableItems : Int {      case TableSections1      case TableSections2      case TableSections3      case TableSections4 } class TableSec