计算机专业毕业外文文献翻译.docx
《计算机专业毕业外文文献翻译.docx》由会员分享,可在线阅读,更多相关《计算机专业毕业外文文献翻译.docx(14页珍藏版)》请在冰豆网上搜索。
计算机专业毕业外文文献翻译
XX大学
毕业设计(论文)说明书
英文翻译
专业
网络工程
班级
姓名
XX
学号
指导教师
XX
二OXX年六月十六日
外文文献翻译
Originalcontent:
JackNutting,FredrikOlsson,DaveMark,Jeff,LaMarche著.BeginningiOS7DevelopmentExploringtheiOSSDK[M].Apress.2014.03.19.
What’sDifferentAboutCodingforiOS?
IfyouhaveneverprogrammedinCocoaoritspredecessorsNeXTSTEPorOpenStep,youmayfindCocoaTouch—theapplicationframeworkyou’llbeusingtowriteiOSapplications—alittlealien.Ithassomefundamentaldifferencesfromothercommonapplicationframeworks,suchasthoseusedwhenbuilding.NETorJavaapplications.Don’tworrytoomuchifyoufeelalittlelostatfirst.Justkeeppluggingawayattheexercises,anditwillallstarttofallintoplaceafterawhile.
IfyouhavewrittenprogramsusingCocoaorNeXTSTEP,alotintheiOSSDKwillbefamiliartoyou.AgreatmanyclassesareunchangedfromtheversionsthatareusedtodevelopforOSX.
Eventhosethataredifferenttendtofollowthesamebasicprinciplesandsimilardesignpatterns.However,severaldifferencesexistbetweenCocoaandCocoaTouch.
Regardlessofyourbackground,youneedtokeepinmindsomekeydifferencesbetweeniOSdevelopmentanddesktopapplicationdevelopment.Thesedifferencesarediscussedinthefollowingsections.
OnlyOneActiveApplication
OniOS,onlyoneapplicationcanbeactiveanddisplayedonthescreenatanygiventime.SinceiOS4,applicationshavebeenabletoruninthebackgroundaftertheuserpressesthe“home”button,buteventhatislimitedtoanarrowsetofsituations,andyoumustcodeforit,specifically.
Whenyourapplicationisn’tactiveorrunninginthebackground,itdoesn’treceiveanyattentionwhatsoeverfromtheCPU,whichwillwreakhavocwithopennetworkconnectionsandthelike.iOSallowsbackgroundprocessing,butmakingyourappsplaynicelyinthissituationwillrequiresomeeffortonyourpart.
OnlyOneWindow
Desktopandlaptopoperatingsystemsallowmanyrunningprogramstocoexist,eachwiththeabilitytocreateandcontrolmultiplewindows.However,iOSgivesyourapplicationjustone“window”toworkwith.Allofyourapplication’sinteractionwiththeusertakesplaceinsidethisonewindow,anditssizeisfixedatthesizeofthescreen.
LimitedAccess
Programsonacomputerprettymuchhaveaccesstoeverythingtheuserwholaunchedthemdoes.
However,iOSseriouslyrestrictswhatyourapplicationcanaccess.
YoucanreadandwritefilesonlyfromthepartofiOS’sfilesystemthatwascreatedforyourapplication.Thisareaiscalledyourapplication’ssandbox.Yoursandboxiswhereyourapplicationwillstoredocuments,preferences,andeveryotherkindofdataitmayneedtoretain.
Yourapplicationisalsoconstrainedinsomeotherways.YouwillnotbeabletoaccesslownumbernetworkportsoniOS,forexample,ordoanythingelsethatwouldtypicallyrequirerootoradministrativeaccessonadesktopcomputer.
LimitedResponseTime
Becauseofthewayitisused,iOSneedstobesnappy,anditexpectsthesameofyourapplication.
Whenyourprogramislaunched,youneedtogetyourapplicationopen,preferencesanddataloaded,andthemainviewshownonthescreenasfastaspossible—innomorethanafewseconds.
Atanytimewhenyourprogramisrunning,itmayhavetherugpulledoutfromunderit.Iftheuserpressesthehomebutton,iOSgoeshome,andyoumustquicklysaveeverythingandquit.Ifyoutakelongerthanfivesecondstosaveandgiveupcontrol,yourapplicationprocesswillbekilled,regardlessofwhetheryoufinishedsaving.ThereisanAPIthatallowsyourapptoaskforadditionaltimetoworkwhenit’sabouttogodark,butyou’vegottoknowhowtouseit.
LimitedScreenSize
TheiPhone’sscreenisreallynice.Whenintroduced,itwasthehighestresolutionscreenavailableonahandheldconsumerdevice,byfar.
ButtheiPhonedisplayjustisn’tallthatbig,andasaresult,youhavealotlessroomtoworkwiththanonmoderncomputers.Thescreenisjust320×480onthefirstfewiPhonegenerations,anditwaslaterdoubledinbothdirectionsto640×960withtheintroductionoftheiPhone4’sretinadisplay.Thiswasrecentlyincreasedfurtherto640×1136ontheiPhone5.Thatsoundslikeadecentnumberofpixels,butkeepinmindthattheseretinadisplaysarecrammedintoprettysmallformfactors,soyoucan’tcountonfittingmorecontrolsoranythinglikethat.ThishasabigimpactonthekindsofapplicationsandinteractivityyoucanofferonaniPhone.
TheiPadincreasestheavailablespaceabitbyofferinga1024×768display;buteventoday,that’snotsoterriblylarge.Togiveaninterestingcontrast,atthetimeofwritingApple’sleastexpensiveiMacsupports1920×1080pixels,anditsleastexpensivenotebookcomputer,the11-inchMacBookAir,supports1366×768pixels.Ontheotherendofthespectrum,Apple’slargestcurrentmonitor,the27-inchLEDCinemaDisplay,offersawhopping2560×1440pixels.NotethatneweriPadmodels(everyfull-sizeiPadaftertheiPad2,aswellastheiPadMiniRetina)haveretinadisplaysthatdoublethescreenresolutioninbothdirections.ButaswiththeretinaiPhones,that2048×1536screenisinthesamephysicalspaceastheoldscreenwas,soyoucan’treallycountonusingthosepixelsthesamewayyouwouldonatraditionalscreen.
LimitedSystemResources
Anyold-timeprogrammerswhoarereadingthisarelikelylaughingattheideaofamachinewithatleast512MBofRAMand16GBofstoragebeinginanywayresource-constrained,butitistrue.DevelopingforiOSisnot,perhaps,inexactlythesameleagueastryingtowriteacomplexspreadsheetapplicationonamachinewith48KBofmemory.ButgiventhegraphicalnatureofiOSandallitiscapableofdoing,runningoutofmemoryisveryeasy.
TheiOSdevicesavailablerightnowhaveeither512MB(iPhone4S,iPad2,originaliPadmini,latestiPodtouch),or1024MBofphysicalRAM(iPhone5c,iPhone5s,iPadAir,iPadminiRetina),thoughthatwilllikelyincreaseovertime.Someofthatmemoryisusedforthescreenbufferandbyothersystemprocesses.Usually,nomorethanhalfofthatmemoryisleftforyourapplicationtouse,andtheamountcanbeconsiderablyless,especiallynowthatotherappscanberunninginthebackground.
Althoughthatmaysoundlikeitleavesaprettydecentamountofmemoryforsuchasmallcomputer,thereisanotherfactortoconsiderwhenitcomestomemoryoniOS.ModerncomputeroperatingsystemslikeOSXwilltakechunksofmemorythataren’tbeingusedandwritethemouttodiskinsomethingcalledaswapfile.Theswapfileallowsapplicationstokeeprunning,evenwhentheyhaverequestedmorememorythanisactuallyavailableonthecomputer.iOS,however,willnotwritevolatilememory,suchasapplicationdata,outtoaswapfile.Asaresult,theamountofmemoryavailabletoyourapplicationisconstrainedbytheamountofunusedphysicalmemoryintheiOSdevice.
CocoaTouchhasbuilt-inmechanismsforlettingyourapplicationknowthatmemoryisgettinglow.Whenthathappens,yourapplicationmustfreeupunneededmemoryorriskbeingforcedtoquit.NoGarbageCollection,but...
WementionedearlierthatCocoaTouchusesObjective-C,butoneofthekeyObjective-Cfeaturesoftheearly2000sisnotavailablewithiOS:
CocoaTouchdoesnotsupportgarbagecollection.TheneedtodomanualmemorymanagementwhenprogrammingforiOShasbeenabitofastumblingblockformanyprogrammersnewtotheplatform,especiallythosecomingfromlanguagesthatoffergarbagecollection.
WiththeversionofObjective-CsupportedbythelatestversionsofiOS,however,thisparticularstumblingblockisbasicallygone.ThisisthankstoafeaturecalledAutomaticReferenceCounting(ARC),whichgetsridoftheneedtomanuallymanagememoryforObjective-Cobjects.ARCnotonlyservesasaworthyreplacementtogarbagecollection,it’sactuallybetterinmostrespects.
StartinginOSX10.8,ARCbecamethedefaultmemorymanagementtechnologyforMacapps,andgarbagecollectionhasbeendeprecatedthereinfavorofARC.Andofcourse,it’salsothedefaultmemorymanagementmechanisminiOSaswell.We’lltalkaboutARCinChapter3.
SomeNewStuff
Sincewe’vementionedthatCocoaTouchismissingsomefeaturesthatCocoahas,itseemsonlyfairtomentionthattheiOSSDKcontainssomefunctionalitythatisnotcurrentlypresentinCocoaor,atleast,isnotavailableoneveryMac:
TheiOSSDKprovidesawayforyourapplicationtodeterminetheiOSdevice’scurrentgeographiccoordinatesusingCoreLocation.
MostiOSdeviceshavebuilt-incamerasandphotolibraries,andtheSDKprovidesmechanismsthatallowyourapplicationtoaccessboth.
iOSdeviceshavebuilt-inmotionsensorsthatletyoudetecthowyourdeviceisbeingheldandmoved.
ADifferentApproach
TwothingsiOSdevicesdon’thaveareaphysicalkeyboardandamouse,whichmeansyouhaveafundamentallydifferentwayofinteractingwiththeuserthanyoudowhenprogrammingforageneral-purposecomputer.Fortunately,mostofthatinteractionishandledforyou.Forexample,ifyouaddatextfieldtoyourapplication,iOSknowstobringupakeyboardwhentheusertouchesthatfield,withoutyouneedingtowriteanyextracode.
TheXcodeProjectWindow
Afteryoudismissthesavesheet,Xcodewillcreateandthenopenyourproject.Youwillseeanewprojectwindowx(seeFigure2-5).There’salotofinformationcrammedintothiswindow,andit’swhereyouwillbespendingalotofyouriOSdevelopmenttime.
EvenifyouareanoldhandwithearlierversionsofXcode,you’llstillbenefitfromreadingthroughthissectionsinceitcoversalotofthe