1. Home
  2. /
  3. Objective-c
  4. /
  5. Prime Checker

Prime Checker - Objective-c Typing CST Test

Loading…

Prime Checker — Objective-c Code

Checks if numbers are prime.

#import <Foundation/Foundation.h>

BOOL isPrime(int n){
	if(n<2) return NO;
	for(int i=2;i*i<=n;i++){
		if(n%i==0) return NO;
	}
	return YES;
}

int main(int argc, const char * argv[]) {
	@autoreleasepool {
		int nums[] = {7,10,13};
		for(int i=0;i<3;i++){
		NSLog(@"%d is %@", nums[i], isPrime(nums[i])?@"Prime":@"Not Prime");
		}
	}
	return 0;
}

Objective-c Language Guide

Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to C. It has been the primary language for macOS and iOS development before Swift, enabling developers to create applications for Apple platforms with dynamic runtime capabilities.

Primary Use Cases

  • ▸macOS and iOS application development
  • ▸Legacy Apple framework integration
  • ▸Developing Cocoa and Cocoa Touch applications
  • ▸Creating reusable Objective-C libraries
  • ▸High-performance system-level Apple apps

Notable Features

  • ▸Object-oriented with classes and categories
  • ▸Dynamic runtime with message passing
  • ▸Automatic Reference Counting (ARC) for memory management
  • ▸Protocol-based polymorphism
  • ▸Interoperable with C and C++ code

Origin & Creator

Developed in the early 1980s by Brad Cox and Tom Love, combining C with Smalltalk-style object-oriented messaging.

Industrial Note

Objective-C remains critical for maintaining legacy macOS and iOS applications and for interfacing with older Apple frameworks that are not fully migrated to Swift.

More Objective-c Typing Exercises

Objective-C Counter and Theme ToggleObjective-C Random Number GeneratorObjective-C Todo ListObjective-C Dice RollerObjective-C Countdown TimerObjective-C Temperature ConverterObjective-C Shopping CartObjective-C Name GreetingObjective-C Stopwatch

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher