Chapter13~26:OC Basic - <Objective-C Programming>

#include vs. #import

A message send


class methods vs. instance methods

A message with an argument

a message send with three arguments


alloc and init


sending message to nil

id

memory management

how to declare instance variable and instance methods

#import <> vs. #import ""

using custom classes

setter and getter

setter and getter naming conventions


using properties replace instance variables
#import <Foundation/Foundation.h>
#import "BNRPerson.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // create an intance of BNRPerson
        BNRPerson *mikey = [[BNRPerson alloc]init];
        // give the instance variables interesting values using setters
        [mikey setHeightInMeters:1.8];
        [mikey setWeightInKilos:96];
        
        // log the instance variables using the getters
        float mikeyHeight = [mikey heightInMeters];
        int mikeyWeight = [mikey weightInKilos];
        NSLog(@"mikey is %.2f meters tall and weighs %d kilograms", mikeyHeight, mikeyWeight);
        

        // log some values using custom methods;
        float mikeyBMI = [mikey bodyMassIndex];
        NSLog(@"mikey has a BMI of %f", mikeyBMI);

        
    }
    return 0;
}

dot notation

Another attribute that you will see shortly is copy. Practically speaking, whenever you declare a property that points to an NSString or an NSArray, you should include the copy attribute


override and super

inheritance hierarchy


hierarchy of BMI


description and %@

@class vs. import

class extensions

isEqual vs. identical



immutable objects

sort


define

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容