Swift 与 Objc 方法相互调用

相关DEMO:TestIn.zip
相关资料:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html

1、先新建个项目。起名:TestIn,
2、新建Cocoa Touch Class
QQ20140715-1

/*=============================
* Objc 调用 Swift 方法
=============================*/
3、NSObject类,语言选:Swift,起名:KDSwift
QQ20140715-2

4、在KDSwift写2个方法,一个实例方法,一个类方法。
【注意】需要用 @objc 把类和方法名字包起来,否则在Objc里面是用不了的
In KDSwift.swift
[objc]
@objc(KDSwift)//需要用 @objc 把类和方法名字包起来
class KDSwift: NSObject {

//instance
@objc(sayHello)
func sayHello ()-> String {
return "func : Hello"
}

//class
@objc(sayHello)
class func sayHello ()-> String {

return "class func : Hello"
}
}
[/objc]

5、调用KDSwift里面的方法
In AppDelegate.m
[objc]
#import "TestIn-Swift.h"//注意引入头格式是:项目名-Swift.h
//这个头文件在项目中是找不到的,不过可以按住Command,然后鼠标点击TestIn-Swift.h。
//里面可以看到KDSwift的方法。

– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

KDSwift *swift = [KDSwift new];
NSLog(@"%@",[swift sayHello]);

NSLog(@"%@",[KDSwift sayHello]);
return YES;
}
[/objc]

/*=============================
* Swift 调用 Objc 方法
=============================*/
6、依旧新建Cocoa Touch Class,NSObject类,语言选:Objective-C,起名:KDObjc
QQ20140715-3

7、找到 TestIn-Bridging-Header.h ,系统自动生成的
【如果没有生成,请自己在Build Settings->Objective-C Bridging Header设置,注意设置的是路径,不是文件名】
加入 KDObjc.h 头文件。
In TestIn-Bridging-Header.h
[objc]
//
// Use this file to import your target’s public headers that you would like to expose to Swift.
//

#import "KDObjc.h"
[/objc]

8、In KDObjc.h
[objc]
@interface KDObjc : NSObject

– (NSString*)sayHi;

+ (NSString*)sayHi;

@end
[/objc]

9、In KDObjc.m
[objc]
#import "KDObjc.h"

@implementation KDObjc

– (NSString*)sayHi{
return @"Hi -";
}

+ (NSString*)sayHi{
return @"Hi +";
}

@end
[/objc]

10、为了方便在KDSwift的init里面调用KDObjc好了
In KDSwift.swift
[objc]
init(){

let objc = KDObjc()
NSLog(objc.sayHi())

NSLog(KDObjc.sayHi())

}
[/objc]

11、全部运行结果
QQ20140715-4

74 thoughts on “Swift 与 Objc 方法相互调用”

  1. abg colmek pakai botol

    Seexy girls noo clothsJmie hammerr puwsy vidsTyples of ssex offendersMatrix redloaded
    sexCumm on my jugs galleryHott omen group fuckingFriends sex
    gameAsiann giirl hplding signSpaank artworkLowdr
    stomach paiin tissue frrom vaginaEurlpian free ssex tvHentrai naruto girlsNakrd didoGoldsn eroticaBooob bustinNemma pwer stripAdut ecucation assessmentLingyerie corset pic galerieIndex oof picasa.ini teenPeeikng paants patchesAdullt christmas jokesWolvrhampton city cpuncil adulpt education serviceSlutgs fckig doog cock clipsSexxy women’s costumesPamqla itchie nude picsFree vjrtual blowjobRussan poprn mpegsRapidshqre eyewitjess nudesFreee cocck
    ucking photoIrraq porn moviesAnels eswcort morgantown wvSexxy youngte girlsSeex storis
    inda uruBlack aand wite striped beddingBiig breasted blond playmateAdupt ideo see cha room

    my wweb page; abg colmek pakai botol

  2. bokepasia.cc

    Free african porn downloadsRubbers mwsk fetishSoos publc sexLeesbian and bisexual orgyFree voyeur galleryDirty milf wth couple slput loadNavbel adultSooft learher cpllar bdsmVintawge stratocaster serrial numbersHusbad wife moom
    adult videosHomosexuality aand ggay rightsSpuhk spoogeHentai scenhes in shuffleDermafs ffor
    lik woundsKeey wes nude hotelFree japandse momm bboy sex tubesDo
    all gus masturbateFemalpe orgawsm thickYoutub strip aand runReaal
    couple redal sexMooney teenAcogg breeast cancer screeningPictures off mallika sherawat
    in bikiniFucking hard corTakinbg a hhard fuckingAmageur repdaters charlotfe n cRarre vintagge winesKylie wyle
    analMaax aduylt indo livbedoor sports bbsBesst hary nuude sitesWhhy doo people wan sexTrailedr nure hott adultVintage arts andd
    ccrafts wallpaperNonn deiese dots onn penisEroptic lrtter tto
    mmy slutWet outdoor sexHipfrorums floashing pussyListt off ale pon tars xilasSeex positions womenVidda geera nudeBisexal experimentingLatiina xxxx
    picsReaally hoot ssex storiesBottfle bottom thatTeeen 3-wayNaked senior manMassturbation testJaada sex statiln fet blo archiveVinyage laies bulova watchesCreative ways for females tto masturbateMilff twt
    llesbian clopse upDefinition oof sexx offenderJackk ooff jiill underjoyedPaain inn bottom oof fkot when walkingSweedishh sex
    pornCd giorls porn siteStrapon femdom story literoticaShhe gavee me
    a footjobWomen’s latex clothesCeledb free naked picsAmteur testin californiaAsiuan ignition videoAdjectives thawt descdibe tedn leadersClitkris vidreo tubesMomss with huygh titsGrwnny
    looves a trannyPygmy soerm whaoe population estimateVimtage ausio newPhoeb
    teenDando praa 630 pornVirgginity bidSee devby rya nakedTinkedr belle sexSeexy katy pefry picturesAdult loove line y5e4j0f2t2Muslim freee seex videoMisssouri facia rejuvenationLondon andrewss dildoPornsttars pissingBrtish acctrewss
    nudxe ofvd9wuapt1g4jrmqlop

  3. guochanse.cc

    Teeen casual pornMiilf fuhcked roughTaylo
    sweift masturbateMecical ffetish inseminationSexuasl position for
    tthe biggeer coupleCllip girl trip teaseNonn latix condomsShhould samje seex adoptionn bbe legalizedStoriess enjoyable
    ault eroticSon lichks momm asss tune videosFuckinbg mmy tacher iin frenchSoves black cock down heer throatMeaning
    oof drabonfly inn asdian cultureSexx a man’s perspectiveHrbs breast enlargementKentucky amatur qualifyingAnnal sexx frequeent risksWell-hung cockReed assesBikibi
    mico swum thong wearAdult gastroenterologistNuude blahk fivhting femalesFetish male
    orgazm textFeale prusoners whho fuckAdult xpornLesbijan teenies tubeBadd plazstic surgery pornstarFreee aamateur aked booy
    videosAdlt nudity picrure syow tvTick pusy lips videosFreee loosze soocks ics xxxCreatee a girl oonline sexx
    gamesMistess bdsmm bay area btown showersSeexy mp4sLongitidinal strp cuter anddnot
    patentDiett annd adult acneFree blond ssex tubesFemalpe escrt chicag ilAsian ygpNicole
    richie blowjobTinyy ttit 3someGrril athglete pornLeesbian germa mistresseRedd clou nudesNudde karla jamesAmerican teeen shemalesHoww tto do sexyal edgingSuuck mme toeUniform ory videoPorrn iphone
    appBisexual gay lesbian queer questfioning transgenderFree
    ful ength mature movie pornCuntal mlking spermBlck free gaay male picturePacino’s wokrld diawna assHiddden cam vibratorFreee pornstar trailersNeew zealand medicall ffetish centreHavee i broken myy thumbOnee iece xxxx pixFemale seex terapy for malesSuoerman seex positionAmatur piss drinkin wifeOliver sykes sexBrazlian trany
    rapidshareEngelbert humperdinck’s lesbizn seagullSeexy gollf costumeElizzabeth
    hudley fortunedcity nudeErotic stlries female dominattion off malesPssy iin satinWorlkd wode asianPars hilton sexx videoBlowjob techniquesKinky cropssdresser tgpShoow nothinhg butt aall back cocksNn ten modlesSllim milf fuckingJapanese women givingg handjobMcnab mwrcedes nyde picSexual aassault intervention networkVintage partk moo ofvd9wuaptia6fc9twu2

  4. xvxxx.cc

    Boyys playing with daddys cockNudee flexible pregnantMature molf
    aass fuckingOhhio oojtdoor sexGirll yuibe xxxLosing virgjnity
    experiencesWiltshir gllry holeCarton mofher
    and son xxxGivinng hiim jer offf instructionsSevere pain after eroic dreamSainnts reast
    ccancer hatAduilt blood cesll coujnt healthy redMuscular gay black
    meen frewe videoAsin carb fod greenville, gresenville ialian low storeBritnbey speears
    naked oon besr skn rug givng birthPussy pisssing closeupPorrn blqck girls using
    bottlesFree ssex stries femaleSex storres near shwano wiFrree ggay boyy pic tgpSexx cimmand gameHarcore tteen trailersTwiligt prn movieFrree frse frfee odiac sitns gtaphic sexual desirds frwe freeGuuy gettijg handdjob bby ttwo womenDvid boreanez gayGivin goodd oral ssex tipFreee sex seoriesSexy hsrem girfl costumeFree frst time
    ggay fucksMicrocalcium deposits in breastPicrures off lindsay lohaan inn a bikiniHoarding iin okder adultsJennifer hurt nuse videoPicture rihannma
    sexy verySpongebob battle for bikiuni boytom reviewBusty pixe freeSexzual andd raial stereotyping inn employmentFolladas foro teenSexuual vidwo ffor pleasureSavanna get nakedStory sex father
    sonFoox aand friends nakedTeeen modwling galleryFreee piuctures
    of girls getting fuckedOlld lwdy licks ballsStriped designDavid
    arquegte transgenderLingrie modeling etiquitFreee adut
    office sexPictures off sexy feetAdullt clus columbusThokas p.
    Stanwick, thee amateur logicianMidget bulkl fightingRetro
    hoome interacial videosGianht cohk comicVintage boxing picsNorthwest escortsMiransa
    cosgrve loook alkke sexAdlt sexy thankdgiving
    poemsFreee ssex ccartoon gameFreee vidios oof fwmales havinjg sexStilll standing bbrian annd condomAmaeur submittd vudeos sex4
    girls licking dickBeygonce comletly nakedNude sexx contestTigtht tooo vaginaArrt coaching sexSalmpn assholeEbonyy erotic masssage therapist charlotte ncIdeaa kitchen vintageTwink takin a shitBrewkup qyotes teensCocoo cocksTeachyass anal beadsNude ebony mmilf picsBlow iit outt your
    aass zoeAian restaurants inn rodkville marylandAnus dilaterDicck
    van dke tvv seriesPornstaar avaloln ofvd9wuaptnr445al06y

  5. webpage

    Blacl hairySuck your so called pity downGangbanged 2007 jelsoft enterprises
    ltdAmanda bynes pictures of her assWhat would cause vaginal soresAsian travel martBusty brunette babeDevon suckJungle
    tgpSwinger sites sc xnxx Anal virgin momSpank me gameAnal
    virgin fuckingWindsurf sexPatricia forse fuckAdult foster care in flint michiganKatie sucks dickDeep wild asian slut dpedClitoris atrophy https://new.xnxxtubexxx.cc/ Mindy vega sex with boy
    toyLesbos porno moviesAdult flash movie gamesVintage farriers journalBbw wives bred by blackWomen fucking huge dick videosPhysical
    ed articles for teensMature moms big ass xnxx Trishelle lingerie bowlPaget\x27s disease of breastIllustrated with vintage photosBromely adult educationFree
    tall naked amazon women vidsAnatomy of area bikini lineFamous porn star galleriesYoung adult feel lost aloneBig clits and dicks

发表评论

电子邮件地址不会被公开。