iOS basic question One

Source: Internet
Author: User

First, Jane Answer 1, the following methods of the method name is?
-(void) person-(void) personwithage;-(void) Personwithage: (int) age;-(void) Personwithage: (int) Age Name: (NSString *) Name
A: What are the differences between Person/personwithage/personwithage:/Personwithage:name:2, Nsarray and Nsset?     (1) The Nsarray is orderly, and the nsset is disordered.     (2) Nsarray data can be the same, but Nsset data is not the same. (3) When searching for an element, nsset efficiency is higher than nsarray, because Nsset uses an algorithm hash. For example, if you want to store and access a data element A, a hash algorithm can find the location and storage location where a should be stored directly. Nsarray, however, needs to traverse the entire array. 3. Define a block variable with no parameter return value, and call this block? No return value, no parameter of block
-(void) blockwithoutparameterandreturndata{    void (^myblock) (void)  = ^ {        NSLog (@ "This is a block without Parameter and returned value ");    };    Myblock ();}
4. Define a block variable with a parameter and return value, and call this block?
      -(void) addparameterandrestunvaluesforblock{    int (^blocknames) (int) = ^ (int num) {        return num *;    };    int result = Blocknames (2);    NSLog (@ "%d", result);
5. Do you know what Swift is?          Talk about the current understanding of it? Swift is a new development language developed by Apple, which is based on the C language and is more flexible and convenient than objective-c. In the near future Swift will replace Objective-c as the primary language for iOS development.          6. What are the differences between strong and weak references? A strong reference is a holding object, a weak reference is a non-holding object, a strong reference can free an object, but a weak reference cannot, when an object is a strong reference, outside its scope, the object held by the object is freed, and when an object is a weak reference, it does not hold an object and is automatically assigned nil after the object is disposed.       7, strong, weak, assign each use the occasion is what?     Assign is used for simple data types, such as Nsinteger,double,bool.     In the ARC environment, the strong replaces the retain,weak instead of the assign, while in the loop, one end uses the strong, and the other end uses the weak to prevent loop calls. OC object types are generally used strong.8, classification (category) What is the role of
    • Scatter the implementation of a class into multiple different files or multiple frameworks.
    • Creates a forward reference to a private method.
    • Adds an informal agreement to an object.
Simply put: Category can extend the class to add its own methods to all classes.          9. Talk about your understanding of self and super? In my worldview, self is a hidden parameter to a class that points to the class that is currently calling the method, while super refers to the parent class. Using super will tell the compiler to call the method of the parent class. Super is just a compile indicator.10. What code does the compiler automatically generate when it encounters the following code?
   Self.age =;           Automatic generation [set STAGE:20];     int age = Self.age;      To be perfected     nsarray *names = @[@ "MJ" @ "JJ" @ "Jay"];   Nsarray *names = [[Nsarray alloc] initwithobjects:@ "MJ", @ "JJ", @ "Jay", Nil];     ID money = @20;                Auto-generated:    nsnumber *money1 = [[NSNumber alloc] initwithint:20];
Second, the programming question 11, uses two different ideas to write the function to calculate the following formula: 1+2+3+4+ ... +n (N>=1) (PS: Altogether to write two functions, just for/while/do between the replacement of not a new idea) idea one:
-(Nsinteger) AddToN1: (Nsinteger) n {    Nsinteger total = 0;    for (int. i=1;i<=n;i++) {total        +=i;    }    return total;}
Thinking two,
  -(Nsinteger) AddToN2: (Nsinteger) n {    Nsinteger total = 0;    Total = N (n+1)/2;    return total;     }
12. Use category to add a method to a class (which class thinks) to do the following: Suppose a variable oc array holds many integer strings, such as @ "10", @ "20". After calling this method, the numeric characters in this array are sorted in ascending order, (arranged from small to large)
     nsmutablearray+additions.h////nsmutablearray+additions.h//mianshidemo////Created by Zhanggui on 15/7/19.//Cop Yright (c) 2015 Zhanggui. All rights reserved.//#import <Foundation/Foundation.h> @interface Nsmutablearray (additions) + (Nsmutablearray *  ) Sortvalues: (Nsmutablearray *) Mutablearray; @endNSMutableArray +additions.m////nsmutablearray+additions.m// mianshidemo////Created by Zhanggui on 15/7/19.//Copyright (c) 2015 Zhanggui. All rights reserved.//#import "Nsmutablearray+additions.h" @implementation Nsmutablearray (additions) + (        Nsmutablearray *) Sortvalues: (Nsmutablearray *) mutablearray{nscomparator Findersort = ^ (id string1,id string2) {        if ([string1 integervalue]>[string2 IntegerValue]) {return (Nscomparisonresult) nsordereddescending; }else if ([string1 integervalue]<[string2 IntegerValue]) {return (Nscomparisonresult) nsorderedasce        nding; }else {return (Nscomparisonresult) NsorderEdsame;    }    };    Nsmutablearray *arr= [[Nsmutablearray alloc] initwithcapacity:[mutablearray Count]];    Nsarray *sortedarr = [Mutablearray sortedarrayusingcomparator:findersort];    for (int i=0;i<[mutablearray count];i++) {[arr Addobject:[sortedarr objectatindex:i]; } return arr;}    @end test method:-(void) viewdidload {[Super viewdidload];    Nsmutablearray *mutablearray = [[Nsmutablearray alloc] initwithobjects:@ "5" @ "@" @ "3" @ "@" @ "@", nil]; NSLog (@ "%@", [Nsmutablearray Sortvalues:mutablearray]);} 13. Use category to add a Run method (object method) to all OC objects, and then nslog the print object itself in the Run method: Nsobject+additions.h////nsobject+additions.h//Mian shidemo////Created by Zhanggui on 15/7/19.//Copyright (c) 2015 Zhanggui. All rights reserved.//#import <Foundation/Foundation.h> @interface nsobject (additions)-(void) run; @endNSObject +additions.m////nsobject+additions.m//mianshidemo////Created by Zhanggui on 15/7/19.//Copyright (c) 2015 Zhanggui . All Rights reserved.//#impOrt "Nsobject+additions.h" @implementation nsobject (additions)-(void) run{NSLog (@ "%@", self);} @end
14, use category to add the following functions to the NSString class (need to use the method to check data or guess)
    • Calculates the number of English letters (e.g. @ "235432534rre4645eer", returns 6 after calling the method)
    • string inversion (e.g. @ "ABC", after call output @ "CBA")
    • Remove whitespace at both ends of the string (e.g. @ "Jack Roce", return @ "Jack Rose" after the call)
    • Intercepts a string between www. and. com in the website domain name (e.g. @ "http://www.baidu.com", output Baidu).
  nsstring+additions.h////nsstring+additions.h//mianshidemo////Created by Zhanggui on 15/7/19.//Copyright (c) 2015 Year Zhanggui. All rights reserved.//#import <Foundation/Foundation.h> @interface nsstring (additions)/** determine the number of letters contained in the NSString */ -(Nsinteger) getnumberofletterinstring; /** Invert string */-(NSString *) reversalstring;//delete start and end strings-(NSString *) deletebackandforwardblank;//Get domain name-(NSString *) Getdominfromweblink; @end nsstring+additions.m////nsstring+additions.m//mianshidemo////Created by Zhanggui on 15 /7/19.//Copyright (c) 2015 Zhanggui. All rights reserved.//#import "Nsstring+additions.h" @implementation nsstring (additions)-(Nsinteger)    getnumberofletterinstring{Nsinteger strlength = self.length;    int result = (int) strlength;        for (int i=0;i<strlength;i++) {char-c = [self characteratindex:i];            if (c>= ' 0 ' && c<= ' 9 ') {//judgment is not a number result = Result-1;        NSLog (@ "Number:%c", c); }} return result; -(Nsstring *) reversalstring{nsmutablestring *s = [nsmutablestring string];    Nsuinteger length = self.length;    for (Nsuinteger i=length;i>0;i--) {[s appendstring:[self substringwithrange:nsmakerange (i-1, 1)]; } return s;} -(NSString *) deletebackandforwardblank{nsstring *trimmedstring = [Self stringbytrimmingcharactersinset:[nscharacter      Set Whitespaceandnewlinecharacterset]]; return trimmedstring;}    -(NSString *) getdominfromweblink{nsstring *tempstring = [NSString string];    Nsrange Wwwrange = [self rangeofstring:@ "www."];    Nsrange Comrange = [self rangeofstring:@ ". com"]; Nsrange Needrange =nsmakerange (wwwrange.length+wwwrange.location,    Comrange.location-wwwrange.location-wwwrange.length);    tempstring = [self substringwithrange:needrange]; return tempstring;} @end
15, define a book class, need to have name, price, publication year (such as 2014) three member attributes, create 5 book objects, attributes can be arbitrary value, but the name does not use Chinese
    • Add a convenient construction method (factory method) for quickly creating objects
    • When using NSLog direct output book object, to ensure that the output string format is: This book is called XX, the price is XX, the publication year is XX
    • 5 Book objects in accordance with the year of publication-"Price-" name priority from small to large (the same publication year according to Price, the same price according to the name of the order)

iOS basic question One

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.