Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:02:17+00:00 2026-06-14T00:02:17+00:00

-(NSMutableArray *)sortArrayByProminent:(NSArray *)arrayObject { NSArray * array = [arrayObject sortedArrayUsingComparator:^(id obj1, id obj2) {

  • 0
-(NSMutableArray *)sortArrayByProminent:(NSArray *)arrayObject
{
    NSArray * array = [arrayObject sortedArrayUsingComparator:^(id obj1, id obj2) {
        Business * objj1=obj1;
        Business * objj2=obj2;
        NSUInteger prom1=[objj1 .prominent intValue];
        NSUInteger prom2=[objj2 .prominent intValue];
        if (prom1 > prom2) {
            return NSOrderedAscending;
        }
        if (prom1 < prom2) {
            return NSOrderedDescending;
        }
        return NSOrderedSame;
    }];

    NSMutableArray *arrayHasBeenSorted = [NSMutableArray arrayWithArray:array];

    return arrayHasBeenSorted;
}

So basically I have this block that I use to sort array.

Now I want to write a method that return that block.

How would I do so?

I tried

+ (NSComparator)(^)(id obj1, id obj2)
{
    (NSComparator)(^ block)(id obj1, id obj2) = {...}
    return block;
}

Let’s just say it doesn’t work yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:02:20+00:00Added an answer on June 14, 2026 at 12:02 am

    A method signature to return a block like this should be

    +(NSInteger (^)(id, id))comparitorBlock {
        ....
    }
    

    This decomposes to:

    +(NSInteger (^)(id, id))comparitorBlock;
    ^^    ^      ^  ^   ^  ^       ^
    ab    c      d  e   e  b       f
    
    a = Static Method
    b = Return type parenthesis for the method[just like +(void)...]
    c = Return type of the block
    d = Indicates this is a block (no need for block names, it's just a type, not an instance)
    e = Set of parameters, again no names needed
    f = Name of method to call to obtain said block
    

    Update: In your particular situation, NSComparator is already of a block type. Its definition is:

    typedef NSComparisonResult (^NSComparator)(id obj1, id obj2);
    

    As such, all you need to do is return this typedef:

    + (NSComparator)comparator {
       ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NSMutableArray *array = [[NSArray alloc] initWithObjects:@Apranax Forte, @Actified, @Zostex 125 MG, @Zoprotec 30 MG,
NSMutableArray*array = [[NSMutableArray alloc]init]; NSArray*Somearray = [NSArray arrayWithObjects:1st Object,2ndObject,3rd Object,4th object,5th Object,nil]; In the
NSMutableArray *Number=[NSArray arrayWithObjects: @1, @2, @3, @4, @5, @6, nil]; I have an array
NSMutableArray *output = [[NSMutableArray alloc]init]; or NSArray *output = [[NSMutableArray alloc]init]; I can set
-(NSMutableArray *)processResult:(NSArray*)matchArray removeString:(NSString *)removeStr{ NSString *newLink; NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[matchArray count]]; //doing
When I initialize self.nsmutableArray = [NSMutableArray array]; in my viewDidLoad method NSMutableArray initialize correctly
I have NSMutableArray* names , which contains NSStrings. I want to sort the array
What NSMutableArray methods correspond to these Javascript Array methods? shift(); unshift(); slice(); splice();
NSMutableArray *tmpMutArr = [NSMutableArray arrayWithArray:allObjectsArray]; NSLog(@The content of array is%@,tmpMutArr); int index; for (int
I have an NSMutableArray (detailsMA)having 100 strings like @True. Am storing that array in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.