@@ -21,34 +21,46 @@ class AppDelegateLinker {
2121
2222 logn ( 'Linking AppDelegate...' ) ;
2323
24- var appDelegateContents = fs . readFileSync ( this . appDelegatePath , 'utf8' ) ;
24+ // New flow for Swift
25+ if ( nodePath . extname ( this . appDelegatePath ) === '.swift' ) {
26+ debugn ( 'Entering Swift flow ...' ) ;
27+ var appDelegateContents = fs . readFileSync ( this . appDelegatePath , 'utf8' ) ;
28+ appDelegateContents = this . _extendRNNAppDelegateSwift ( appDelegateContents ) ;
29+ fs . writeFileSync ( this . appDelegatePath , appDelegateContents ) ;
30+ this . removeUnneededImportsSuccess = true
31+ this . removeApplicationLaunchContentSuccess = true
32+
33+ } else { // Old flow for Objective-C
34+ debugn ( 'Entering Objective-C flow ...' ) ;
35+ var appDelegateContents = fs . readFileSync ( this . appDelegatePath , 'utf8' ) ;
36+
37+ if ( this . appDelegateHeaderPath ) {
38+ var appDelegateHeaderContents = fs . readFileSync ( this . appDelegateHeaderPath , 'utf8' ) ;
39+ appDelegateHeaderContents = this . _extendRNNAppDelegate ( appDelegateHeaderContents ) ;
40+ fs . writeFileSync ( this . appDelegateHeaderPath , appDelegateHeaderContents ) ;
41+ }
2542
26- if ( this . appDelegateHeaderPath ) {
27- var appDelegateHeaderContents = fs . readFileSync ( this . appDelegateHeaderPath , 'utf8' ) ;
28- appDelegateHeaderContents = this . _extendRNNAppDelegate ( appDelegateHeaderContents ) ;
29- fs . writeFileSync ( this . appDelegateHeaderPath , appDelegateHeaderContents ) ;
30- }
43+ try {
44+ appDelegateContents = this . _removeUnneededImports ( appDelegateContents ) ;
45+ this . removeUnneededImportsSuccess = true ;
46+ } catch ( e ) {
47+ errorn ( ' ' + e . message ) ;
48+ }
3149
32- try {
33- appDelegateContents = this . _removeUnneededImports ( appDelegateContents ) ;
34- this . removeUnneededImportsSuccess = true ;
35- } catch ( e ) {
36- errorn ( ' ' + e . message ) ;
37- }
50+ appDelegateContents = this . _importNavigation ( appDelegateContents ) ;
3851
39- appDelegateContents = this . _importNavigation ( appDelegateContents ) ;
52+ appDelegateContents = this . _bootstrapNavigation ( appDelegateContents ) ;
4053
41- appDelegateContents = this . _bootstrapNavigation ( appDelegateContents ) ;
54+ try {
55+ appDelegateContents = this . _removeApplicationLaunchContent ( appDelegateContents ) ;
56+ this . removeApplicationLaunchContentSuccess = true ;
57+ } catch ( e ) {
58+ errorn ( ' ' + e . message ) ;
59+ }
4260
43- try {
44- appDelegateContents = this . _removeApplicationLaunchContent ( appDelegateContents ) ;
45- this . removeApplicationLaunchContentSuccess = true ;
46- } catch ( e ) {
47- errorn ( ' ' + e . message ) ;
61+ fs . writeFileSync ( this . appDelegatePath , appDelegateContents ) ;
4862 }
4963
50- fs . writeFileSync ( this . appDelegatePath , appDelegateContents ) ;
51-
5264 if ( this . removeUnneededImportsSuccess && this . removeApplicationLaunchContentSuccess ) {
5365 infon ( 'AppDelegate linked successfully!\n' ) ;
5466 } else {
@@ -178,6 +190,19 @@ class AppDelegateLinker {
178190 _doesImportNavigation ( content ) {
179191 return / # i m p o r t \s + \< R e a c t N a t i v e N a v i g a t i o n \/ R e a c t N a t i v e N a v i g a t i o n .h > / . test ( content ) ;
180192 }
193+
194+ // SWIFT implementation
195+ _extendRNNAppDelegateSwift ( content ) {
196+ return content
197+ . replace (
198+ / i m p o r t R e a c t _ R C T A p p D e l e g a t e / ,
199+ 'import ReactNativeNavigation'
200+ )
201+ . replace (
202+ / c l a s s A p p D e l e g a t e : R C T A p p D e l e g a t e / ,
203+ 'class AppDelegate: RNNAppDelegate'
204+ )
205+ }
181206}
182207
183208module . exports = AppDelegateLinker ;
0 commit comments