0Pricing
SwiftUI Academy · درس

المسندات الشرطية ومسندات الترتيب

صفِّ النتائج التي جرى جلبها ورتّبها

المسندات الشرطية ومسندات الترتيب درس مجاني في SwiftUI Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في SwiftUI Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Shaping Your Results

As data grows you rarely want every row. Predicates and sort descriptors let you fetch just the right slice.

What a Predicate Is

An NSPredicate is a rule that decides which records match, written in a compact query-like format string.

NSPredicate(format: "isDone == true")

Comparing Values

Use operators like ==, >, and < in the format string to match numbers, dates, and other fields.

NSPredicate(format: "priority > 2")

Safe Arguments

Insert dynamic values with %@ placeholders instead of string-building, which is safer and clearer.

NSPredicate(format: "title == %@", searchText)

Text Matching

Match partial text with CONTAINS, and add [c] to ignore case for friendly search.

NSPredicate(format: "title CONTAINS[c] %@", query)

Combining Conditions

Join rules with AND and OR to express more specific filters in one predicate.

NSPredicate(format: "isDone == false AND priority > 1")

What a Sort Descriptor Is

A SortDescriptor tells Core Data which attribute orders the rows, and in which direction.

SortDescriptor(\.title, order: .forward)

Multiple Sort Keys

Pass an array of descriptors to break ties, like sorting by priority first, then by name.

[SortDescriptor(\.priority), SortDescriptor(\.title)]

Using Them in @FetchRequest

Combine both in a @FetchRequest to fetch a filtered, ordered set right inside your view.

@FetchRequest(sortDescriptors: [SortDescriptor(\.title)], predicate: NSPredicate(format: "isDone == false")) var tasks: FetchedResults<Task>

Filtering Beats Looping

Letting the store filter and sort is faster than fetching everything and trimming it in Swift. ⚡

Update Filters Live

You can rebuild a predicate from a search field and reassign it, so results refine as the user types.

Quick Check

You can now filter and order data. Quick check on the tools.

Recap

You used predicates to filter records and sort descriptors to order them, fetching exactly the data each screen needs. ✨

الأسئلة الشائعة

هل درس «المسندات الشرطية ومسندات الترتيب» مجاني؟

نعم — نص درس «المسندات الشرطية ومسندات الترتيب» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة SwiftUI Academy، انتقل إلى CoddyKit PRO. تتضمن دورة SwiftUI Academy 4 دروس في المجموع.

ماذا ستتعلم في «المسندات الشرطية ومسندات الترتيب»؟

صفِّ النتائج التي جرى جلبها ورتّبها تتمرن على SwiftUI Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ SwiftUI Academy؟

لا تُشترط خبرة سابقة. SwiftUI Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «المسندات الشرطية ومسندات الترتيب»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس SwiftUI Academy هذا؟

نعم. كل درس في SwiftUI Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. حزمة Core Data
  2. الجلب باستخدام @FetchRequest
  3. إنشاء الكيانات وحفظها
  4. المسندات الشرطية ومسندات الترتيب
← العودة إلى SwiftUI Academy