iOS:Objective-C学习入门随手记

2016年05月12日 iOS 20条评论 阅读6278次

方法前的 + 代表 静态方法。无需实例化该类即可调用该方法

方法前的 - 代表 动态方法。必须实例化该类才可调用该方法


object-c:bean类及其初始化


面向对象思想中很重要的一点就是万物即对象。
既然是对象则一般就会有属性方法等。
因此,我们有必要为常用到的对象创建一个bean的类。

在object-c中,创建一个类很简单。下面是以一个市场可能具有的相关属性作为对象的bean类。

@interface MarketBean : NSObject {
    NSString *name;
    NSString *type;
    NSString *location;
}
- (id)initWithName:(NSString *)name Type:(NSString *)type Loction:(NSString *) loc;
+ (id)marketWithName:(NSString *)name Type:(NSString *)type Loction:(NSString *) loc;
@end

@implementation MarketBean

-(id)initWithName:(NSString *)name Type:(NSString *)type Loction:(NSString *) loc {

    if (self = [super init]) {
        _name = name;
        _type = type;
        _location = location;
    }
    return self;
}
@end



Object-C的便利构造器

还有一种被称为便利构造器的构造方法是更常用的更简单的。
在初始化方法的基础上进行了封装,即封装了对象的创建过程。便利构造器是“+”号方法,返回 本类型 的实例,方法名以类名开头。根据需求不同,可以没有参数、或多个参数。
内部实现,封装了alloc和初始化方法。

+(id) marketWithName:(NSString *)name Type:(NSString *)type Location:(NSString *)loc {
    id obj = [[MarketBean alloc] initWithName:name Type:type Location:loc];
    [obj autorelease];
    return obj;
}


注意[obj autorelease]一句,我在xcode7(iOS9)下用的时候,有编译错误的提示。
ARC

分享本文至:

WRITTEN BY

avatar
本文标签:iOSobjective-c
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

20 条评论

  1. <a href="http://www.drcooper.net/nike-zoom-pegasus-31-herren-schuhe-outlet-butya">nike zoom pegasus 31 herren schuhe outlet</a> <a href="http://www.drinkableair.net/asics-gel-quantum-360-mennns-r%C3%B8d-eye-schuhea">asics gel quantum 360 mennns r酶d eye</a>
    adultlivesexx http://www.adultlivesexx.net/

  2. <a href="http://www.rcrocs.com/nike-blazer-high-womens-blue-white-shoesl">nike blazer high womens blue white</a> <a href="http://www.moreheaddotts.com/polo-ralph-lauren-usa-hoodie-poloh">polo ralph lauren usa hoodie</a> <a href="http://www.qgchsmrt.com/adidas-nmd-runner-hvid-sort-skok">adidas nmd runner hvid sort</a> <a href="http://www.firagandia.com/adidas-tubular-doom-triple-schwarz-review-schuheh">adidas tubular doom triple schwarz review</a> <a href="http://www.lmladeco.com/nike-air-pegasus-83-university-red-shoesk">nike air pegasus 83 university red</a> <a href="http://www.brinkmanmdc.com/kvinder-nike-dunk-high-flying-pig-lyser%C3%B8d-skol">kvinder nike dunk high flying pig lyser酶d</a>
    rolandviet http://www.rolandviet.com/

  3. <a href="http://www.starizle.com/lunarglide-6-bianca-dots-obuvf">lunarglide 6 bianca dots</a> <a href="http://www.notpotatoes.com/nike-air-max-2014-violet-bleu-ciel-kurpese">nike air max 2014 violet bleu ciel</a> <a href="http://www.tedxuon.com/air-jordan-future-rojo-and-blanco-kurpesf">air jordan future rojo and blanco</a> <a href="http://www.thejuicylucy.com/kvinners-nike-flyknit-lunar-1-bl%C3%A5-gr%C3%B8nn-schuheg">kvinners nike flyknit lunar 1 bl氓 gr酶nn</a> <a href="http://www.almanyaonline.com/nike-zoom-pegasus-33-dam%C3%A4nner-blau-orange-scarpef">nike zoom pegasus 33 dam盲nner blau orange</a> <a href="http://www.trademelikes.com/nike-basketball-gull-rosa-kurpesa">nike basketball gull rosa</a>
    intspv http://www.intspv.com/

  4. <a href="http://www.flockandvine.com/nike-air-huarache-nero-laser-arancia-butya">nike air huarache nero laser arancia</a> <a href="http://www.formasindo.com/adidas-yeezy-boost-350-b%C3%B8rn-brun-hvid-butyc">adidas yeezy boost 350 b酶rn brun hvid</a> <a href="http://www.covergirlmag.com/nike-mercurial-superfly-naranja-test-scarpeg">nike mercurial superfly naranja test</a> <a href="http://www.fuckitmusic.com/adidas-tubular-runner-weave-rosado-plata-chaussuresb">adidas tubular runner weave rosado plata</a> <a href="http://www.mpdcir.com/air-max-95-schwarz-grape-butya">air max 95 schwarz grape</a> <a href="http://www.faketheenvy.com/air-jordan-future-gull-himmelen-bl%C3%A5-schuhee">air jordan future gull himmelen bl氓</a>
    dblynx http://www.dblynx.com/

  5. <a href="http://www.kanseisc.com/nike-internationalist-damen-wolf-grey-shoesj">nike internationalist damen wolf grey</a> <a href="http://www.pragaoviedo.com/rvca-all-the-way-mens-trucker-hat-hath">rvca all the way mens trucker hat</a> <a href="http://www.turamodenovia.com/nike-air-max-invigor-zapatilla-de-deporte-squadron-azul-photo-zapatosl">nike air max invigor zapatilla de deporte squadron azul photo</a> <a href="http://www.redfiveonline.com/nike-air-jordan-6-retro-black-shoesk">nike air jordan 6 retro black</a> <a href="http://www.hoangkang.com/mennns-nike-air-max-1-gr%C3%B8nn-obuvi">mennns nike air max 1 gr酶nn</a> <a href="http://www.valaseif.com/kvinner-nike-lab-air-max-270-rosa-gr%C3%A5-hvit-obuvk">kvinner nike lab air max 270 rosa gr氓 hvit</a>
    ayakkabiyeri http://www.ayakkabiyeri.com/

  6. <a href="http://www.abartz.com/nike-blazers-armada-azul-mujeres-kurpesa">nike blazers armada azul mujeres</a> <a href="http://www.howatshives.com/nike-free-3.0-cortuttio-kurpesc">nike free 3.0 cortuttio</a> <a href="http://www.codedtalk.com/adidas-pr%C3%B8dator-s%C3%B8lv-jewelry-obuva">adidas pr酶dator s酶lv jewelry</a> <a href="http://www.bcrailroad.com/air-max-90-essential-blanco-woman-schuhef">air max 90 essential blanco woman</a> <a href="http://www.glutenfreebay.com/adidas-nmd-runner-core-noir-orange-chaussuresg">adidas nmd runner core noir orange</a> <a href="http://www.dexterbowl.com/nike-air-max-2017-blanco-and-negro-pants-obuvd">nike air max 2017 blanco and negro pants</a>
    bladeid http://www.bladeid.com/

  7. <a href="http://www.yogafriendly.com/nike-flyknit-racer-volt-svart-and-hvit-obuvk">nike flyknit racer volt svart and hvit</a> <a href="http://www.btvspassion.com/purchase-latest-nike-kwazi-action-hvit-r%C3%B8d-obuvi">purchase latest nike kwazi action hvit r酶d</a> <a href="http://www.trusejenta.com/nike-air-force-1-low-blanco-precio-zapatosl">nike air force 1 low blanco precio</a> <a href="http://www.chatgroupies.com/maschio-air-max-2016-verde-blu-nero-scarpeh">maschio air max 2016 verde blu nero</a> <a href="http://www.tamarindoyam.com/adidas-superstar-all-black-mens-shoesk">adidas superstar all black mens</a> <a href="http://www.tinaandcoco.com/ray-ban-wayfarer-blue-frame-sunglassesh">ray ban wayfarer blue frame</a>
    bazicloob http://www.bazicloob.com/

  8. <a href="http://www.goodmedusa.com/nike-air-max-classic-nero-pelle-scarpeh">nike air max classic nero pelle</a> <a href="http://www.murskacorp.com/adidas-superstar-80s-white-shoesk">adidas superstar 80s white</a> <a href="http://www.prajansim.com/ray-ban-aviator-58-sunglassesh">ray ban aviator 58</a> <a href="http://www.pokersurga.com/nike-lunar-gato-2-jaune-chaussuresl">nike lunar gato 2 jaune</a> <a href="http://www.arkmmj.com/hommes-nike-air-max-2019-noir-chaussuresl">hommes nike air max 2019 noir</a> <a href="http://www.butterbroad.com/nike-air-max-2014-m%C3%A4nner-grau-gr%C3%BCn-blau-schuhej">nike air max 2014 m盲nner grau gr眉n blau</a>
    cksholdings http://www.cksholdings.com/

  9. <a href="http://www.sguerradesign.com/adidas-zx-flux-mens-white-shoesh">adidas zx flux mens white</a> <a href="http://www.zeneventsja.com/nike-air-huarache-femminile-oro-nero-scarpei">nike air huarache femminile oro nero</a> <a href="http://www.adharaweb.com/nike-kobe-9-premium-gorge-gr%C3%BCn-schuhej">nike kobe 9 premium gorge gr眉n</a> <a href="http://www.jrelselaw.com/new-york-knicks-new-era-nba-retro-basic-9fifty-snapback-cap-hath">new york knicks new era nba retro basic 9fifty snapback cap</a> <a href="http://www.intellalegal.com/nike-air-force-1-noir-turbo-vert-chaussuresh">nike air force 1 noir turbo vert</a> <a href="http://www.carmelscoffee.com/nike-zoom-winflo-3-argento-grigio-scarpeq">nike zoom winflo 3 argento grigio</a>
    swisshomeas http://www.swisshomeas.com/

  10. avatar voydnet

    <a href="http://www.snifferwalk.com/nike-shox-blau-orangen-schuhel">nike shox blau orangen</a> <a href="http://www.fishmackerel.com/nike-air-max-tn-femmes-bleu-blanc-chaussuresq">nike air max tn femmes bleu blanc</a> <a href="http://www.lauraenergy.com/nike-flyknit-racer-hombresta-verde-zapatosl">nike flyknit racer hombresta verde</a> <a href="http://www.magellantt.com/nike-air-presto-ultra-flyknit-atlantic-bl%C3%A5-skoj">nike air presto ultra flyknit atlantic bl氓</a> <a href="http://www.sportablecrew.com/air-jordan-retro-1-mint-gr%C3%B8nn-gamma-bl%C3%A5-obuvi">air jordan retro 1 mint gr酶nn gamma bl氓</a> <a href="http://www.digisolnc.com/ua-micro-g-torch-gris-azul-zapatosp">ua micro g torch gris azul</a>
    voydnet http://www.voydnet.com/

  11. avatar cynshq

    <a href="http://www.kainjipark.com/new-york-rangers-7-rod-gilbert-green-salute-to-service-stitched-nhl-jersey-nflg">new york rangers 7 rod gilbert green salute to service stitched nhl jersey</a> <a href="http://www.lapthelakes.com/orange-pink-womens-adidas-springblade-pro-shoes-runningf">orange pink womens adidas springblade pro shoes</a> <a href="http://www.delmaroffice.com/nfl-pittsburgh-steelers-color-rush-limited-antonio-brown-mens-football-jersey-nflv">nfl pittsburgh steelers color rush limited antonio brown mens football jersey</a> <a href="http://www.medieneinsatz.com/kyrie-1-white-and-orange-trainersa">kyrie 1 white and orange</a> <a href="http://www.linexcanton.com/lebron-soldier-10-gul-low-scarpec">lebron soldier 10 gul low</a> <a href="http://www.saskostomy.com/air-jordan-retro-6-mintgr%C3%B8n-s%C3%B8lv-kurpesc">air jordan retro 6 mintgr酶n s酶lv</a>
    cynshq http://www.cynshq.com/

  12. avatar magellantt

    <a href="http://www.yeliseeva.com/air-jordan-true-flight-blu-arancia-scarpel">air jordan true flight blu arancia</a> <a href="http://www.miembrojr.com/aidas-boost-clima-chill-blue-black-shoesj">aidas boost clima chill blue black</a> <a href="http://www.faridekhalaf.com/cheap-michael-kors-clutch-bag-mkh">cheap michael kors clutch bag</a> <a href="http://www.rawbiofast.com/nike-zoom-winflo-3-bl%C3%A5-hvit-obuvi">nike zoom winflo 3 bl氓 hvit</a> <a href="http://www.mabarrel.com/nike-free-inneva-tech-bianca-scarpej">nike free inneva tech bianca</a> <a href="http://www.almarsecurity.com/nike-roshe-run-hyperfuse-red-bestellen-shoesh">nike roshe run hyperfuse red bestellen</a>
    magellantt http://www.magellantt.com/

  13. avatar allthatspool

    <a href="http://www.miendiation.com/nike-hypershift-isaiah-thomas-for-sale-cheap-runningf">nike hypershift isaiah thomas for sale cheap</a> <a href="http://www.powfarm.com/nfl-pittsburgh-steelers-color-rush-limited-antonio-brown-mens-football-jersey-nflv">nfl pittsburgh steelers color rush limited antonio brown mens football jersey</a> <a href="http://www.nongmobacon.com/nike-air-max-ebay-philippines-trainersa">nike air max ebay philippines</a> <a href="http://www.rentalloka.com/nike-kobe-10-poison-gr%C3%B8n-card-scarpec">nike kobe 10 poison gr酶n card</a> <a href="http://www.casamentosweb.com/nike-kaishi-gr%C3%BCn-lila-kurpesc">nike kaishi gr眉n lila</a> <a href="http://www.perheopas.com/ray-ban-sunglasses-bangalore-prices-drop-sunglassesg">ray ban sunglasses bangalore prices drop</a>
    allthatspool http://www.allthatspool.com/

  14. avatar nrastogi

    <a href="http://www.daddeaze.com/air-jordan-1-sort-high-chaussuresa">air jordan 1 sort high</a> <a href="http://www.debracousins.com/new-york-rangers-red-jersey-nflc">new york rangers red jersey</a> <a href="http://www.yankaripark.com/nike-lebron-11-kvinders-gr%C3%B8n-runningg">nike lebron 11 kvinders gr酶n</a> <a href="http://www.yicailottery.com/35-authentic-grant-hill-detroit-pistons-jersey-mens-adidas-nba-purple-throwback-1995-all-nflv">35 authentic grant hill detroit pistons jersey mens adidas nba purple throwback 1995 all</a> <a href="http://www.calebcraw.com/nike-air-max-thea-schwarz-grau-39-trainersa">nike air max thea schwarz grau 39</a> <a href="http://www.liquidputter.com/nike-air-max-95-jacquard-braun-gold-scarpec">nike air max 95 jacquard braun gold</a>
    nrastogi http://www.nrastogi.com/

  15. avatar ascential

    <a href="http://www.bursatiket.net/nike-flyknit-air-max-sensor-for-salg-chaussuresf">nike flyknit air max sensor for salg</a> <a href="http://www.buxpix.net/nike-air-max-zero-marina-militare-bianca-obuvc">nike air max zero marina militare bianca</a> <a href="http://www.buyggauto.net/nike-kd-9-sort-and-hvid-quartz-kurpesb">nike kd 9 sort and hvid quartz</a> <a href="http://www.carlinandcompany.net/nike-lunar-hyperdunk-2013-venta-kurpese">nike lunar hyperdunk 2013 venta</a> <a href="http://www.carrymebike.net/nike-air-force-1-mid-gr%C3%B8nn-gr%C3%A5-kurpesd">nike air force 1 mid gr酶nn gr氓</a> <a href="http://www.casatienda.net/jordan-11-gamma-bleu-keychain-scarped">jordan 11 gamma bleu keychain</a>
    ascential http://www.ascential.net/

  16. avatar xb7fksnt

    <a href="http://www.febrsjsq.com/nike-flyknit-lunar-1-wolf-gr%C3%A5-kvinners-schuhed">nike flyknit lunar 1 wolf gr氓 kvinners</a> <a href="http://www.eh440fwo.com/nike-tanjun-negro-blanco-kurpese">nike tanjun negro blanco</a> <a href="http://www.yz413tae.com/jordan-1-flight-2-low-schwarz-obuva">jordan 1 flight 2 low schwarz</a> <a href="http://www.kojqfbo6.com/nike-blazer-high-vintage-scarpe-da-ginnastica-nero-sail-obuvf">nike blazer high vintage scarpe da ginnastica nero sail</a> <a href="http://www.eax5s1up.com/kobe-10-amarillo-obuvf">kobe 10 amarillo</a> <a href="http://www.iumtx7cb.com/adidas-zx-flux-bl%C3%A5-and-svart-schuhef">adidas zx flux bl氓 and svart</a>
    xb7fksnt http://www.xb7fksnt.com/

  17. avatar tabbstore

    <a href="http://www.alfiekaye.com/nike-air-jordan-1-retro-high-og-noir-chaussuresa">nike air jordan 1 retro high og noir</a> <a href="http://www.buyincar.com/adidas-neo-svart-uk-butya">adidas neo svart uk</a> <a href="http://www.clearvieweps.com/nike-huarache-ultra-khaki-for-salg-obuvc">nike huarache ultra khaki for salg</a> <a href="http://www.financesmiled.com/air-huarache-todas-rojo-zephyr-scarpea">air huarache todas rojo zephyr</a> <a href="http://www.getwichquick.com/asics-gel-hyper-33-2-kvinders-l%C3%B8b-sko-you-tube-scarpee">asics gel hyper 33 2 kvinders l酶b sko you tube</a> <a href="http://www.kareokiparty.com/nike-internationalist-mid-l%C3%A6r-sneaker-kits-obuvc">nike internationalist mid l忙r sneaker kits</a>
    tabbstore http://www.tabbstore.com/

  18. avatar shamankin

    <a href="http://www.myoastudies.com/limited-nike-pink-womens-joe-haden-jersey-nfl-23-pittsburgh-steelers-rush-fashion-nflu">limited nike pink womens joe haden jersey nfl 23 pittsburgh steelers rush fashion</a> <a href="http://www.reganwhimpey.com/lebron-12-low-orange-hvid-opinie-kurpesb">lebron 12 low orange hvid opinie</a> <a href="http://www.segurotiendas.com/femmes-nike-air-presto-bleu-blanc-schuhec">femmes nike air presto bleu blanc</a> <a href="http://www.specpilot.com/nike-free-flyknit-5.0-viola-schuheg">nike free flyknit 5.0 viola</a> <a href="http://www.texaschambers.com/nike-free-flyknit-4.0-l%C3%B8b-sko-kvinders-yelp-kurpesc">nike free flyknit 4.0 l酶b sko kvinders yelp</a> <a href="http://www.waughjiujitsu.com/femmes-air-jordan-retro-3-or-bleu-obuvg">femmes air jordan retro 3 or bleu</a>
    shamankin http://www.shamankin.com/

  19. avatar vorax

    <a href="http://www.mkdeltalandsgroup.net/nike-air-max-1-ultra-2.0-le-casual-chaussures-butya">nike air max 1 ultra 2.0 le casual chaussures</a> <a href="http://www.mlarchitects.net/free-run-2-wolf-grigio-jack-schuheg">free run 2 wolf grigio jack</a> <a href="http://www.mobilesoccerclub.net/air-max-2016-blau-orange-theatre-butyf">air max 2016 blau orange theatre</a> <a href="http://www.moonandcompany.net/jordan-prime-fly-2-gr%C3%B8nn-butya">jordan prime fly 2 gr酶nn</a> <a href="http://www.mosesbodyshop.net/jordan-1-negro-gris-2013-obuvb">jordan 1 negro gris 2013</a> <a href="http://www.mrmpageantgowns.net/nike-lebron-13-low-team-rouge-online-scarped">nike lebron 13 low team rouge online</a>
    [url=http://www.vorax.net/]vorax[/url]

  20. avatar treehousecats

    <a href="http://www.tipicousa.com/mackage-military-coat-mackager">mackage military coat</a> <a href="http://www.reprebates.com/moncler-coat-bloomingdale-discount-liquors-monclerd">moncler coat bloomingdale discount liquors</a> <a href="http://www.goeaglepointe.com/ray-ban-tech-aviator-sunglassesr">ray ban tech aviator</a> <a href="http://www.ykloans.com/mulberry-daria-clutch-purple-haze-mulberryg">mulberry daria clutch purple haze</a> <a href="http://www.servicioswom.com/adidas-porsche-typ-64-wei%C3%9F-blau-sneakerc">adidas porsche typ 64 wei脽 blau</a> <a href="http://www.drlunaworld.com/parajumpers-gobi-femme-beige-talon-parajumpersf">parajumpers gobi femme beige talon</a>
    treehousecats http://www.treehousecats.com/

欢迎留言




用户登录

sitemap