البرمجة

كيفية استخراج قيم من NSMutableArray في Objective-C

To retrieve values from an NSMutableArray where each object contains multiple values, you can use nested loops as you’ve attempted. However, the syntax for accessing elements of NSMutableArray and NSString is a bit different. Here’s the correct way to do it:

objective
for (int i = 0; i < [array count]; i++) { NSArray *subArray = array[i]; // Assuming each object is an array of NSStrings for (int j = 0; j < [subArray count]; j++) { NSString *value = subArray[j]; NSLog(@"Value at index %d in object %d: %@", j, i, value); } }

This code assumes that array is your NSMutableArray, and each object in array is an NSArray containing NSString values. If your objects are not arrays, you might need to adjust the code accordingly based on the actual structure of your NSMutableArray.

المزيد من المعلومات

بالتأكيد! في Objective-C، يمكنك استخدام الدوال المتاحة في الكلاس NSArray للوصول إلى عناصر المصفوفة الداخلية. على سبيل المثال، يمكنك استخدام الدالة objectAtIndex: للوصول إلى العنصر في موضع محدد داخل المصفوفة الداخلية. إليك مثال:

objective
for (int i = 0; i < [array count]; i++) { NSArray *subArray = [array objectAtIndex:i]; for (int j = 0; j < [subArray count]; j++) { NSString *value = [subArray objectAtIndex:j]; NSLog(@"Value at index %d in object %d: %@", j, i, value); } }

يمكنك أيضًا استخدام الدالة objectAtIndexedSubscript: بدلاً من objectAtIndex: بشكل مباشر كما في المثال التالي:

objective
for (int i = 0; i < [array count]; i++) { NSArray *subArray = array[i]; for (int j = 0; j < [subArray count]; j++) { NSString *value = subArray[j]; NSLog(@"Value at index %d in object %d: %@", j, i, value); } }

هذه الطريقتان متشابهتان في النتيجة، لكن الطريقة الثانية تستخدم عملية فهرسة النص المؤشري لتكون أكثر قراءة وفهمًا.

مقالات ذات صلة

زر الذهاب إلى الأعلى
إغلاق

أنت تستخدم إضافة Adblock

يرجى تعطيل مانع الإعلانات حيث أن موقعنا غير مزعج ولا بأس من عرض الأعلانات لك فهي تعتبر كمصدر دخل لنا و دعم مقدم منك لنا لنستمر في تقديم المحتوى المناسب و المفيد لك فلا تبخل بدعمنا عزيزي الزائر