الصياغة الأساسية وأنواع البيانات
تعلّموا الصياغة الأساسية وأنواع البيانات البدائية وكائنات Objective-C الشائعة مثل NSString وNSArray.
الصياغة الأساسية وأنواع البيانات درس مجاني في Objective-C iOS Development for Legacy & Enterprise Apps على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Objective-C iOS Development for Legacy & Enterprise Apps، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Objective-C iOS Development for Legacy & Enterprise Apps 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Objective-C Basics
Time for the fundamentals: Objective-C's basic syntax and the data types you will work with every day.
Statements End with Semicolons
Like other C-based languages, every Objective-C statement ends with a semicolon. Forget one and Xcode will flag it fast.
Explain Your Code with Comments
Comments are notes the compiler ignores. Use // for a single line and /* */ for multi-line blocks.
Primitive Data Types
Primitive types hold simple values: int, float/double, char, and BOOL (which is YES or NO).
Primitives in Action
Here those primitive types come to life — declared, assigned, and printed with NSLog format specifiers.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
int age = 30;
float price = 19.99f; // 'f' for float literal
double pi = 3.14159;
char initial = 'J';
BOOL isLoggedIn = YES;
NSLog(@"Age: %i", age);
NSLog(@"Price: %.2f", price);
NSLog(@"Pi: %f", pi);
NSLog(@"Initial: %c", initial);
NSLog(@"Logged In: %@", isLoggedIn ? @"YES" : @"NO");
}
return 0;
}Working with Text: NSString
For words and sentences you use the NSString object, not char. NSString is immutable: its contents never change after creation.
NSString Example
Declaring an NSString uses the @ prefix before the literal — a piece of syntax unique to Objective-C.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *greeting = @"Hello, CoddyKit!";
NSString *name = @"Alice";
NSString *message = [NSString stringWithFormat:@"Welcome, %@!", name];
NSLog(@"Greeting: %@", greeting);
NSLog(@"Personal Message: %@", message);
}
return 0;
}Collections: NSArray
NSArray stores an ordered list of objects, accessed by zero-based index. It is immutable; use NSMutableArray when you need to change it.
NSArray Example
Create an NSArray with the @[] literal. The older arrayWithObjects form needs a nil terminator.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// Array literal syntax
NSArray *fruits = @[@"Apple", @"Banana", @"Cherry"];
NSLog(@"First fruit: %@", fruits[0]); // Access by index
NSLog(@"All fruits: %@", fruits);
// Another way to create (older, but good to know)
NSArray *colors = [NSArray arrayWithObjects:@"Red", @"Green", @"Blue", nil];
NSLog(@"Colors: %@", colors);
}
return 0;
}Quick Check on Types
Consider the following Objective-C declarations. Which one correctly defines a boolean variable named isActive and sets it to true?
Recap: Syntax & Data Types
Recap: semicolons end statements, comments document, primitives like int and BOOL hold simple values, and NSString and NSArray handle text and lists.
الأسئلة الشائعة
هل درس «الصياغة الأساسية وأنواع البيانات» مجاني؟
نعم — نص درس «الصياغة الأساسية وأنواع البيانات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Objective-C iOS Development for Legacy & Enterprise Apps، انتقل إلى CoddyKit PRO. تتضمن دورة Objective-C iOS Development for Legacy & Enterprise Apps 4 دروس في المجموع.
ماذا ستتعلم في «الصياغة الأساسية وأنواع البيانات»؟
تعلّموا الصياغة الأساسية وأنواع البيانات البدائية وكائنات Objective-C الشائعة مثل NSString وNSArray. تتمرن على Objective-C iOS Development for Legacy & Enterprise Apps مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Objective-C iOS Development for Legacy & Enterprise Apps؟
لا تُشترط خبرة سابقة. Objective-C iOS Development for Legacy & Enterprise Apps على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «الصياغة الأساسية وأنواع البيانات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Objective-C iOS Development for Legacy & Enterprise Apps هذا؟
نعم. كل درس في Objective-C iOS Development for Legacy & Enterprise Apps يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- مقدمة إلى Objective-C
- الصياغة الأساسية وأنواع البيانات
- إعداد Xcode لـ Objective-C
- التعامل مع NSString وأنواع Foundation